poi の異なる HSSFCell オブジェクトに Image を追加する方法は?
画像を追加するコードをいくつか書きましたが、問題は、セルに最後の画像を追加したことです。そのセルは他のセルが画像を表示していないこと以外の画像のみを表示しています...
あなたの助けに感謝 ...
私のコードは
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;
}