Sorry, I am being really slow this evening.

Firstly, I have had a very quick dig around and I think that there could be
some bad news. The HSSFClientAnchor ties an image to a specific number of
rows and columns; it uses them to calculate the size of the image. So, you
will have to add the image after you have resized the rows and columns to
accomodate it correctly.

However, have you thought of using a template file to base your spreadsheets
upon? You could create a template file with the logo positioned and sized
just as you want it at the top of the sheet. Save that file away and call it
something like template.xls or template.xlt to make it apparant that it is a
template file. Now, when you want to create a file, open the template,
populate the sheet and save it all away under a new/different filename. All
you will need to do is remember where the image ends so that you do not end
up creating cells in a row that would overwrite portions of it.

I know that this example relates to Office 2007 but it may also point you in
an interetsing direction;

http://www.online-tech-tips.com/ms-office-tips/header-on-excel/

as it is entitled how to insert a graphic header...Again, you will be
creating a template through Excel and using that as the basis for your POI
generated files but I reckon that approach should work.

Yours

Mark B


Jon Brisbin-2 wrote:
> 
> I've not found a lot of documentation on how to add images to  
> spreadsheets using POI and the examples I have found don't seem to  
> work like I expect. I could really use some help here.
> 
> I'm trying to add a company logo graphic (which I pull from our  
> intranet via Java URL object) to a HSSFWorkbook I create. My code  
> looks like this:
> 
>      int picIndex = workbook.addPicture(getNPCLogo(),  
> Workbook.PICTURE_TYPE_PNG);
>      Drawing pat = currentSheet.createDrawingPatriarch();
>      HSSFClientAnchor anchor = new HSSFClientAnchor();
>      anchor.setAnchorType(2);
>      anchor.setCol1((short) 0);
>      anchor.setCol2((short) 1);
>      anchor.setRow1(0);
>      anchor.setRow2(1);
>      Picture pic = pat.createPicture(anchor, picIndex);
> 
> The problem I'm having, though, is that this creates an image that  
> fills the height and width of the first cell, which is not what I want  
> (it looks stretched out). What I want is for the image to appear at  
> it's normal width and height at a specific position I give it, but I  
> can't seem to understand how to make that happen. When I replace  
> setCol1 et. al. with setDx1 and setDy1, etc... I get an image that is  
> a fraction of the height and width of the original image. I don't  
> understand what units the setDx2 and setDy2 is expecting (and it's not  
> documented anywhere I've found) so I can't get the image to the right  
> size.
> 
> Can someone please give me some clear guidance (beyond what little  
> code is out there in the wild which I've tried variations on ad  
> nauseum) on how to accomplish this using POI 3.5 beta5? I'm sure I'm  
> just missing a little something that I don't understand but I can't  
> see what that is.
> 
> Thanks!
> 
> Jon Brisbin
> Portal Webmaster
> NPC International, Inc.
> 

-- 
View this message in context: 
http://www.nabble.com/Problems-adding-logo-image-to-spreadsheet-tp23851486p23855274.html
Sent from the POI - User mailing list archive at Nabble.com.


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

Reply via email to