POI Excel HSSFPicture图像和大小

我通过这样的代码将图像添加到工作表:

// 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() ; 

然而,在图像添加之后,我调整了列的大小 – 这似乎弄乱了一切。 它调整图像大小 – 这不是我想要的。

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

如果我不执行autoSizeColumns(),图像是适当的大小。

有什么办法可以兼得?

这是疯狂的,没有多大意义,但分配适当的间距和行数似乎是关键。 我添加了足够的行,以便图像可以在内部绑定到行 – 而且都看起来不错。

道德故事:继续工作和搞乱,最终可能会奏效。 你会感到非常沮丧,也不会有那么多的帮助 – 因为我们这些正确定位图像的人并不真正理解为什么。