Hello, I can't understand an issue related to inserting images in an
HSSFWorkbook. In the example below, if I save a copy of the Workbook
before inserting the second image, the final saved file doesn't display
the second image. On the other hand, if I don't perform the intermediate
saving, the final file is correctly saved as expected.
I have highlighted with asterisks the portion of code that gives the
problem when uncommented:
try {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet 1");
CreationHelper helper = wb.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
{
InputStream is = new FileInputStream(resolvePath("imm1.png"));
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
is.close();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setRow1(1);
anchor.setCol1(2);
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize();
}
//
***************************************************************************************************
// FileOutputStream fileOut1 = new
FileOutputStream(sim.getSessionDir() + File.separator +
"example_image_1.xls");
// wb.write(fileOut1);
// fileOut1.close();
//
***************************************************************************************************
{
InputStream is = new FileInputStream(resolvePath("imm2.png"));
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
is.close();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setRow1(14);
anchor.setRow2(1);
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize();
}
FileOutputStream fileOut2 = new
FileOutputStream(sim.getSessionDir() + File.separator +
"example_image_2.xls");
wb.write(fileOut2);
fileOut2.close();
} catch (IOException ex) {
sim.println(ex);
}
Thanks in advance for telling me whether I am making something wrong or
it is a bug...
Regards,
Flavio
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org