I am also having the same issue. I add an image to say row 1,
 and then later on I try to add an image to say row 45.. and now
the image on row 1 dissapears. I am writing to an xls doc. Here is my code.

public void insertImage(HSSFWorkbook wb) throws Exception
        {
                System.out.println("Pic Loop");
                
                InputStream imgIs = new FileInputStream("C:\\Test\\img.jpeg");  
                byte[] bytes = IOUtils.toByteArray(imgIs);
                int pictureIdx = wb.addPicture(bytes,
org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_JPEG);
                imgIs.close();
                CreationHelper helper = wb.getCreationHelper();
                
                int num = wb.getNumberOfSheets();
                 
                for(int i=0; i<num; i++)
                {
                HSSFSheet sheet = wb.getSheetAt(i);
                Drawing drawing = sheet.createDrawingPatriarch();
                //add a picture shape
            ClientAnchor anchor = helper.createClientAnchor();
            anchor.setCol1(7);
            anchor.setRow1(1);
            Picture pict = drawing.createPicture(anchor, pictureIdx);
            
            sheet.setColumnWidth(7, 3766);
            pict.resize();
                }
        }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to