aka*_*nom 5 java excel groovy apache-poi
我通过以下代码将一个图像添加到工作表中:
// 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() ;
Run Code Online (Sandbox Code Playgroud)
然而,在添加图像之后,我调整了列的大小 - 这似乎搞砸了.它调整了图像的大小 - 这不是我想要的.
//psuedo code
public void autoSizeColumns() {
def cols = (StartColumn..this.cMax)
cols.each { i ->
sheet.autoSizeColumn i
}
}
BrandedWorksheet v;
v.autoSizeColumns()
Run Code Online (Sandbox Code Playgroud)
如果我不执行autoSizeColumns(),则图像大小合适.
有没有办法让两者都有?
这很疯狂,并没有多大意义,但分配适当数量的间距和行似乎是关键.我添加了足够的行,以便图像可以在内部绑定到行 - 而且一切似乎都很好.
故事的道德:继续工作和搞乱,它可能最终奏效.你会感到非常沮丧,并且那里没有大量的帮助 - 因为我们这些有正确尺寸图像的人并不真正理解为什么.