我正在使用 Apache POI-HSSF 将图片添加到单元格中。图像是 120x100,但无论我做什么以及如何调整它,Excel 电子表格总是显示它跨越多行并将其扭曲到比宽度大得多的高度。
如何保持原始尺寸?
我的代码:
InputStream is = new FileInputStream(getImageURL());
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
//add a picture shape
CreationHelper helper = wb.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
// Create the drawing patriarch. This is the top level container for all shapes.
Drawing drawing = sheet1.createDrawingPatriarch();
//set top-left corner of the picture,
//subsequent call of Picture#resize() will operate relative to it
anchor.setAnchorType(0);
anchor.setCol1(1);
anchor.setRow1(1);
Picture pict = drawing.createPicture(anchor, pictureIdx);
//auto-size picture relative to its top-left corner
pict.resize();
我已经尝试了所有 dx/dy 坐标和 Col/Row。位置无关紧要,它水平拉伸图像的问题。