|
|
|||
How can I embed multiple images in Excel using POI?
Hi,
I am able to embed an image to a sheet. But, when I try to embed multiple images to the same sheet giving different anchors, I notice my excel generated with the second image loaded, first image is not displayed. Below is the code I've used to insert images to the sheet. Please guide me if there is anything wrong in the code. public static void addChart(String[] chartFiles, HSSFWorkbook wb, HSSFSheet sheet,int row){ //add chart to this workbook. int col=0; try { for (int i = 0; i < chartFiles.length -1; i++) { InputStream is = new FileInputStream(chartFiles[0]); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = wb.addPicture(bytes, HSSFWorkbook.PICTURE_TYPE_JPEG); is.close(); // Create the drawing patriarch. This is the top level container for all shapes. HSSFPatriarch drawing = sheet.createDrawingPatriarch(); //add a picture shape HSSFClientAnchor anchor = new HSSFClientAnchor(); //set top-left corner of the picture, //subsequent call of Picture#resize() will operate relative to it anchor.setCol1((short)col); anchor.setCol2((short)3); anchor.setRow1(row); HSSFPicture pict = drawing.createPicture(anchor, pictureIdx); //auto-size picture relative to its top-left corner pict.resize(); row+=25; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } Thanks, pp 4 Replies |
|||
|