我正在使用Apache POI-HSSF將圖片添加到單元格中。圖像是120x100,但無論我做什麼以及如何調整它大小,Excel電子表格總是顯示它橫跨多行,並將其扭曲到比寬度大得多的高度。Apache POI-HSSF在將圖片添加到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座標和彩色/行。位置並不重要,它橫向拉伸圖像的問題。由於
我發現這種情況發生在我使用row.setHeight()設置行高時。如果我不這樣做,圖像是好的。無論我身高多大,圖像仍然垂直拉伸。 – 2013-04-24 01:25:35