poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yegor Kozlov <ye...@dinom.ru>
Subject Re: HOWTO create multiple images
Date Wed, 27 Jun 2007 18:19:20 GMT
Hi,

Don't create a drawing patriarch per image. You can have only one drawing patriarch per sheet.
The code below inserts two images in a worksheet.

        FileInputStream is;
        File file;
        byte[] bytes;
        int idx;

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sh = wb.createSheet();
        HSSFPatriarch p = sh.createDrawingPatriarch();

        file = new File("tomcat.png");
        bytes = new byte[(int)file.length()];
        is = new FileInputStream(file);
        is.read(bytes);
        is.close();

        idx = wb.addPicture(bytes, HSSFWorkbook.PICTURE_TYPE_PNG);
        p.createPicture(new HSSFClientAnchor(0, 0, 0, 0, (short)1, 1, (short)4, 10), idx);


        file = new File("clock.jpg");
        bytes = new byte[(int)file.length()];
        is = new FileInputStream(file);
        is.read(bytes);
        is.close();

        idx = wb.addPicture(bytes, HSSFWorkbook.PICTURE_TYPE_JPEG);
        p.createPicture(new HSSFClientAnchor(0, 0, 0, 0, (short)1, 12, (short)4, 30), idx);

        FileOutputStream out = new FileOutputStream("workbook.xls");
        wb.write(out);
        out.close();


> Hi,

> I followed the example
> http://poi.apache.org/hssf/quick-guide.html#Images
> and tried to create multiple PNG or JPEG images. My config follows :-

> Apache Tomcat 4.1.30
> Sun JDK 1.5.0_06
> POI 3.0

> However, there is only one image in the output workbook file, and it is
> always the last inserted image, e.g. the 3rd image if I inserted 3 images
> and the 5th if I inserted 5 images. I hope someone could advise how I could
> insert multiple images onto a workbook file.

> Thanks a lot.

> John Mok

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message