7
如何在poi中的不同HSSFCell对象中添加图像?如何在Apache POI的HSSFCell中添加图片?
我已经写了一些代码,是添加图像,但问题是,小区是我最后添加图像,这仅细胞显示出比其他图像没有其他细胞显示图片...
感谢你的帮助。 ..
我的代码是
while(rs.next()){
HSSFCell cell = getHSSFCell(sheet, rowNo, cellNo);
cell.setCellValue(new HSSFRichTextString(rs.getString("TEST_STEP_DETAILS")));
cell.setCellStyle(style);
String annotate = rs.getString("ANNOTATE");
if(annotate != null){
int index = getPicIndex(wb);
HSSFPatriarch patriarch=sheet.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(400,10,655,200,(short)cellNo,(rowNo+1),(short)cellNo,(rowNo+1));
anchor.setAnchorType(1);
patriarch.createPicture(anchor, index);
}
cellNo++;
}
getPicIndex方法: -
public static int getPicIndex(HSSFWorkbook wb){
int index = -1;
try {
byte[] picData = null;
File pic = new File("C:\\pdf\\logo.jpg");
long length = pic.length();
picData = new byte[ (int) length ];
FileInputStream picIn = new FileInputStream(pic);
picIn.read(picData);
index = wb.addPicture(picData, HSSFWorkbook.PICTURE_TYPE_JPEG);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return index;
}
我发现与解决方案相同...无论如何感谢您的回答... – Garudadwajan 2009-09-29 08:42:04