poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anthony Andrews <pythonadd...@yahoo.com>
Subject Re: Add images to a cell using POI 2.5 ---Help urgent
Date Thu, 07 Dec 2006 13:11:46 GMT
I can think of three possible options.

The first is to look at using an on-activation macro to embed the image for you. I do not
know the VBA code that you would need to use but you can embed a macro in the template spreadsheet
file. This macro will be preserved when you create the final file based upon it and using
POI and it would certainly be the first option I would explore.

Secondly, you could upgrade to a more recent version of POI that will support images.

Finally, you could change to using JExcel rather than POI. I use both and only began to use
JExcel when one of my clients requested a system to prepare invoices using Excel based on
a template that included an image that was their heading.

m-n.rajulah@daimlerchrysler.com wrote: the error is still there ..POI 2.5.1 does not support
this feature .....Is 
there any other way by which this can be implemented ..

 [javac] ExcelKurveAction.java:688: cannot find symbol
    [javac] symbol  : variable PICTURE_TYPE_PNG
    [javac] location: class org.apache.poi.hssf.usermodel.HSSFWorkbook
    [javac] pictureIndex = wb.addPicture( 
bos.toByteArray(),HSSFWorkbook.PICTURE_TYPE_PNG);
    [javac] ^
    [javaca:704: cannot find symbol
    [javac] symbol  : method 
createPicture(org.apache.poi.hssf.usermodel.HSSFClientAnchor,int)
    [javac] location: class org.apache.poi.hssf.usermodel.HSSFPatriarch
    [javac] patriarch.createPicture(anchor, loadPicture( 
"/images/logos/DC.png", wb ));
    [javac] ^
    [javac] Note: * uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 2 errors



pythonaddict@yahoo.com 
06.12.2006 17:35
Bitte antworten an
poi-user@jakarta.apache.org


An
poi-user@jakarta.apache.org
Kopie

Thema
Re: Antwort: Re: Antwort: Re: Antwort: Re: Add images to  a cell using POI 
2.5 ---Help urgent






Not tested this so I cannot be sure but I think it is just a spelling 
error.

You have entered;

wb.addPicture(bos.toByteArray(),HSSFWorkbook.PICTURE_TYP_PNG);

and I think it should be;

wb.addPicture(bos.toByteArray(),HSSFWorkbook.PICTURE_TYPE_PNG);

You may have miss-typed the name of the static variable.

m-n.rajulah@daimlerchrysler.com wrote: 
[javac]reports\action\ExcelKurveAction.java:669: cannot find symbol
    [javac] symbol  : variable PICTURE_TYP_PNG
    [javac] location: class org.apache.poi.hssf.usermodel.HSSFWorkbook
    [javac] pictureIndex = wb.addPicture( 
bos.toByteArray(),HSSFWorkbook.PICTURE_TYP_PNG);
    [javac] ^
    [javac]reports\action\ExcelKurveAction.java:686: cannot find symbol
    [javac] symbol  : method 
createPicture(org.apache.poi.hssf.usermodel.HSSFClientAnchor,int)
    [javac] location: class org.apache.poi.hssf.usermodel.HSSFPatriarch
    [javac] patriarch.createPicture(anchor, loadPicture( 
"/images/logos/DC.png", wb ));
    [javac] ^

Hope this helps 

Regards 



pythonaddict@yahoo.com 
06.12.2006 08:32
Bitte antworten an
poi-user@jakarta.apache.org


An
poi-user@jakarta.apache.org
Kopie

Thema
Re: Antwort: Re: Antwort: Re: Add images to  a cell  using POI 2.5 ---Help 

urgent






What error/exception are you seeing when you try to add the image? Could 
you post the statctrace please - if there is one?

m-n.rajulah@daimlerchrysler.com wrote: private int loadPicture( String 
path, HSSFWorkbook wb ) throws IOException
    {
        int pictureIndex;
        FileInputStream fis = null;
        ByteArrayOutputStream bos = null;
        try
        {
            fis = new FileInputStream( path);
            bos = new ByteArrayOutputStream( );
            int c;
            while ( (c = fis.read()) != -1)
                bos.write( c );
            pictureIndex = wb.addPicture( 
bos.toByteArray(),HSSFWorkbook.PICTURE_TYP_PNG); 
        }
        finally
        {
            if (fis != null)
                fis.close();
            if (bos != null)
                bos.close();
        }
        return pictureIndex;
    }
        private void addLogo( HSSFSheet sheet, HSSFWorkbook wb ) throws 
IOException
    {
                HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        HSSFClientAnchor anchor;
        anchor = new HSSFClientAnchor(0,0,0,100,(short)0,11,(short)0,14);
        //anchor.setAnchorType(2);
        patriarch.createPicture(anchor, loadPicture( 
"/images/logos/DC.png", wb ));
     }

Thanks for the reply ..See I did the following as said in the guide  ..but 


gives error on addPicture () and CreatePicture() ....Iam using POI 2.5 
.Have alook at the code snippet also if needed which states exactly what 
you recomended .. ..also Iam trying to add a image through POI only ..

Thanks n Regards 
HEpzibah







pythonaddict@yahoo.com 
05.12.2006 18:39
Bitte antworten an
poi-user@jakarta.apache.org


An
poi-user@jakarta.apache.org
Kopie

Thema
Re: Antwort: Re: Add images to  a cell  using POI 2.5  ---Help urgent






.png should be fine.

I have cut the folowing from the user guide to see if it helps at all.

                 Images are part of the drawing support.  To add an image 
just                 call createPicture() on the drawing patriarch.    At 
the time of writing the following types are supported: 
 
   PNG
   JPG
   DIB
                               It is not currently possible to read 
existing images and it                 should be noted that any existing 
drawings may be erased                 once you add a image to a sheet. 
 
                  // Create the drawing patriarch.  This is the top level 
container for 
// all shapes. This will clear out any existing shapes for that sheet. 
HSSFPatriarch patriarch = sheet5.createDrawingPatriarch();
HSSFClientAnchor anchor;     anchor = new 
HSSFClientAnchor(0,0,0,255,(short)2,2,(short)4,7); anchor.setAnchorType( 2 


);     patriarch.createPicture(
   anchor, loadPicture( "src/resources/logos/logoKarmokar4.png", wb ));

>From reading that it seems that you will have to insert the image rather 
than copy it from the spreadsheet.

m-n.rajulah@daimlerchrysler.com wrote: Iam using .png 



pythonaddict@yahoo.com 
05.12.2006 13:48
Bitte antworten an
poi-user@jakarta.apache.org


An
poi-user@jakarta.apache.org
Kopie

Thema
Re: Add images to  a cell  using POI 2.5  ---Help urgent






I am pretty sure you should be able to use a template that includes an 
image and then create a workbook based upon that template. What type of 
image are you using (.jpg, .png, .bmp)? It may be that it is simply the 
'wrong' type.

m-n.rajulah@daimlerchrysler.com wrote: I want to have a logo in a cell and 



tried having it part of the template 
and loading it ..
While trying to open gives error which otherwise works perfectly without 
the image ..
Therefore tried the following  code...

But POI 2.5 does not support createPicture() method of patriach and 
addPicture () of workbook ..

Is there  a way out for this ..please help ..


Regards 

Hepzibah

private int loadPicture( String path, HSSFWorkbook wb ) throws IOException
    {
        int pictureIndex;
        FileInputStream fis = null;
        ByteArrayOutputStream bos = null;
        try
        {
            fis = new FileInputStream( path);
            bos = new ByteArrayOutputStream( );
            int c;
            while ( (c = fis.read()) != -1)
                bos.write( c );
            pictureIndex = wb.addPicture( 
bos.toByteArray(),HSSFWorkbook.PICTURE_TYP_PNG); 
        }
        finally
        {
            if (fis != null)
                fis.close();
            if (bos != null)
                bos.close();
        }
        return pictureIndex;
    }
        private void addLogo( HSSFSheet sheet, HSSFWorkbook wb ) throws 
IOException
    {
                HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        HSSFClientAnchor anchor;
        anchor = new HSSFClientAnchor(0,0,0,100,(short)0,11,(short)0,14);
        //anchor.setAnchorType(2);
        patriarch.createPicture(anchor, loadPicture( 
"/images/logos/DC.png", wb ));
     }




 
---------------------------------
Access over 1 million songs - Yahoo! Music Unlimited.


 
---------------------------------
Need a quick answer? Get one in minutes from people who know. Ask your 
question on Yahoo! Answers.


 
---------------------------------
Want to start your own business? Learn how on Yahoo! Small Business.


 
---------------------------------
Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates.


 
---------------------------------
Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates.
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message