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.

Reply via email to