poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "spencer.c" <spencer.criss...@gmail.com>
Subject Adding Picture to Excel Sheet using POI not working.
Date Thu, 19 Jul 2007 14:10:24 GMT

Hello, I'm using POI 3.0.1 final, and trying to add a picture to an excel
sheet that I've got.  I've gone through the archives, and it really seems to
me that the following code ought to be working.  If someone could run an eye
over it, and tell me where I may be going astray, that would be great.  

The code runs, and throws no errors, seems to finish correctly.  But when I
open the sheet, there is no image there.  I added the bit in the middle to
make sure that the bytes for the image are in fact correct, and they are, I
am able to open the written image file without problem.  

    private void embedImage( HSSFWorkbook wb )
        byte[] imgBytes = source.getImageBytes();

        try {
            File f = new File("C:\\output.jpg");

            FileOutputStream fos = new FileOutputStream(f);
        } catch (Exception e) {

        HSSFPatriarch patr = wb.getSheetAt(0).createDrawingPatriarch();
        HSSFClientAnchor a = new HSSFClientAnchor( 1,1,1,1, (short)0, 0,
(short)1, (short)1 );

        int imgHandle = wb.addPicture(imgBytes,
        HSSFSimpleShape shape = patr.createPicture(a, imgHandle);

I've tried the code both with the last line active and commented out,
without visible effect.  Is there anything else I should need to do to add
the image?  Is there anything else I can check in the worksheet itself, or
in the debugger for additional information?  As I say, from all appearances
in the debugger, this works fine, it just doesn't show when I open the

Thanks for your assistance!

View this message in context: http://www.nabble.com/Adding-Picture-to-Excel-Sheet-using-POI-not-working.-tf4111349.html#a11690130
Sent from the POI - User mailing list archive at Nabble.com.

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

View raw message