poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Flavio Cimolin <flavio.cimo...@cd-adapco.com>
Subject Problem with inserting images after saving an HSSFWorkbook
Date Tue, 12 Jun 2012 13:54:12 GMT
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




-- 
Flavio Cimolin
Technical Support Engineer
CD-adapco, Turin Office
phone: +39 011 562 2194 (int 413)
email: flavio.cimolin@cd-adapco.com <mailto:flavio.cimolin@cd-adapco.com>
web: http://www.cd-adapco.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message