我正在通过如下代码向工作表添加图像:
// 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() 图像大小合适。
有什么办法可以兼得吗?
最佳答案
这很疯狂而且没有多大意义,但分配适当的间距和行数似乎是关键。我添加了足够多的行,以便图像可以在内部绑定(bind)到行 - 一切看起来都很好。
这个故事的寓意:继续工作和搞砸,它最终可能会奏效。您会感到非常沮丧,而且那里不会有太多帮助 - 因为我们这些已经正确调整图像大小的人并不真正理解原因。
关于java - POI Excel HSSF图片图像和尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6216667/