POI Excel HSSFPicture Image and Size

I add the image to the worksheet through the following code:

// Create the drawing patriarch.  This is the top level container for all shapes.
Drawing drawing = sheet.createDrawingPatriarch();

//add a picture shape
//ClientAnchor anchor = this.creationHelper.createClientAnchor();
ClientAnchor anchor = new HSSFClientAnchor((short)0, (short)0, (short)0, (short)0, (short)0, (short)0, (short)2, (short)5)

// 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. 
anchor.setAnchorType(2)

HSSFPicture pict = drawing.createPicture(anchor, this.images.get("logo"));
pict.resize() ;

However, immediately after adding the images, I resize the columns, which seems to ruin the situation. It resizes images - this is not what I want.

//psuedo code
public void autoSizeColumns() {
    def cols = (StartColumn..this.cMax)
    cols.each { i ->
        sheet.autoSizeColumn i
    }   
}

BrandedWorksheet v; 
v.autoSizeColumns()

If I do not execute autoSizeColumns (), the image matches the size.

Is there a way to have both?

+5
source share
1 answer

This is crazy and doesn't make much sense, but highlighting the right number of spaces and lines is apparently the key. I have added enough lines so that the image can be attached internally to the lines - and everything seems good.

: , . , , , , , .

+5

All Articles