Download the latest build from trunk and try the following code:

        byte[] pictureData = null; // read from file
        HSSFWorkbook wb = new
                HSSFWorkbook(new FileInputStream("template.xls"));

        int newPictureIndex = wb.addPicture(pictureData,
HSSFWorkbook.PICTURE_TYPE_PNG);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
        for(HSSFShape sh : drawing.getChildren()){
            if(sh instanceof HSSFPicture){
                HSSFPicture pic = (HSSFPicture)sh;
                pic.setPictureIndex(newPictureIndex);
            }
        }

Yegor

On Tue, Aug 16, 2011 at 3:39 PM, Hannes Erven <[email protected]> wrote:
> Folks,
>
>
> I need to batch-replace pictures embedded in Excel 2003 files; that is,
> after the conversion the file should contain a different image, but with
> otherwise the same properties (location, size, ...) as the original.
>
> So far I have found that listing all affected HSSFPictures and
> identifying those that should be replaced is no big deal. I haven't
> found any way to modify the PictureData associated with the HSSFPicture.
>
> With XSSF I'd probably just call getPackagePart().getOutputStream(), but
> with HSSF?
> Unfortunately, the result must absolutely be a XLS file.
>
>
> Thank you for any hints!
>
> Best regards,
>
>        -hannes
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

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

Reply via email to