
注意:以下是用來導出圖檔的代碼,在導出過程中沒有報錯現象
求高三幫忙!謝謝
privatevoidQuotationListReport(ModelList QuotationListReport,
HSSFSheet sheet)throwsIOException {
DynamicMapModelmodel =null;
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFWorkbook wb =newHSSFWorkbook();
if(null!= QuotationListReport) {
for(inti = 1;i
model = (DynamicMapModel) QuotationListReport.getModel(i-1);
HSSFCell r8c1= sheet.getRow(i+6).getCell((short) 0);
r8c1.setEncoding(HSSFCell.ENCODING_UTF_16);
r8c1.setCellValue(i);
HSSFCell r8c2= sheet.getRow(i+6).getCell((short) 1);
r8c2.setEncoding(HSSFCell.ENCODING_UTF_16);
r8c2.setCellValue(model.getParam("VendorPn") ==null?""
: model.getParam("VendorPn").toString());
HSSFCell r8c3= sheet.getRow(i+6).getCell((short) 2);
r8c3.setEncoding(HSSFCell.ENCODING_UTF_16);
r8c3.setCellValue(model.getParam("Model") ==null?""
: model.getParam("Model").toString());
HSSFCell r8c4= sheet.getRow(i+6).getCell((short) 3);
r8c4.setEncoding(HSSFCell.ENCODING_UTF_16);
r8c4.setCellValue(model.getParam("SerialNo") ==null?""
: model.getParam("SerialNo").toString());
HSSFCell r8c5= sheet.getRow(i+6).getCell((short) 4);
r8c5.setEncoding(HSSFCell.ENCODING_UTF_16);
r8c5.setCellValue(model.getParam("FailedSymptom") ==null?""
: model.getParam("FailedSymptom").toString());
HSSFCell r8c7= sheet.getRow(i+6).getCell((short) 6);
r8c7.setEncoding(HSSFCell.ENCODING_UTF_16);
r8c7.setCellValue(model.getParam("Price") ==null?""
: model.getParam("Price").toString());
HSSFCell r8c6= sheet.getRow(i+6).getCell((short) 5);
r8c6.setEncoding(HSSFCell.ENCODING_UTF_16);
HSSFRow row = sheet.createRow(i+6);
row.setHeightInPoints(60);
Blob blob = (Blob) model.getParam("fileContent");
String imgTpye = model.getParam("fileName")==null?"":model.getParam("fileName").toString();
imgTpye = imgTpye.toUpperCase();
if(blob !=null){
ByteArrayOutputStream byteArrayOut =newByteArrayOutputStream();
//String ReturnReason = (String) model.getParam("ReturnReason");
//先把讀進來的圖檔放到一個ByteArrayOutputStream中,以便産生ByteArray
//讀入圖檔1
BufferedImage bufferImg = ImageIO.read(newFile("d:\\W4008612.jpg"));
//如果是從資料庫中讀取的BLOB類型的圖檔
//BufferedImage bufferImg = imgChangeBuffer(blob);
//BUFFER寫入圖檔
if(imgTpye.endsWith(".JPG")){
ImageIO.write(bufferImg,"jpg", byteArrayOut);
HSSFClientAnchor anchor =newHSSFClientAnchor(0, 0, 255, 255,
(short) 5, i+6, (short)6, i+6);
anchor.setAnchorType(3);
patriarch.createPicture(anchor, wb.addPicture(byteArrayOut
.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}elseif(imgTpye.endsWith(".GIF")){//JDK不支援BMP格式的圖片形式,需要對其進行解碼轉換轉碼方法ESBMPImg2PIGUtil
ImageIO.write(bufferImg,"gif", byteArrayOut);
HSSFClientAnchor anchor =newHSSFClientAnchor(0, 0, 255, 255,
(short) 5, i+6, (short)6, i+6);
anchor.setAnchorType(3);
patriarch.createPicture(anchor, wb.addPicture(byteArrayOut
.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
}elseif(imgTpye.endsWith(".PNG")){
ImageIO.write(bufferImg,"png", byteArrayOut);
HSSFClientAnchor anchor =newHSSFClientAnchor(0, 0, 255, 255,
(short) 5, i+6, (short)6, i+6);
anchor.setAnchorType(3);
patriarch.createPicture(anchor, wb.addPicture(byteArrayOut
.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));
}
}
}
}
}