我在插入一張圖片在Excel表單im製作中遇到麻煩。 關於這個問題有很多問題,但我根本無法弄清楚我做錯了什麼。我 代碼運行,顯示沒有錯誤,但我沒有看到的圖像插入:(Apache POI插入圖像
這裏是代碼:
InputStream is = new FileInputStream("nasuto_tlo.png");
byte [] bytes = IOUtils.toByteArray(is);
int pictureIndex = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
is.close();
CreationHelper helper = wb.getCreationHelper();
Drawing drawingPatriarch = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(2);
anchor.setRow1(3);
Picture pict = drawingPatriarch.createPicture(anchor, pictureIndex);
pict.resize();
try {
FileOutputStream out = new FileOutputStream(root+"/Busotina/Busotina1.xls");
wb.write(out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
POI已經有了問題插入Word文檔中的圖片,所以我會認爲這是相關的。 – dkatzel
它在新表上工作嗎? POI只能將圖像添加到沒有任何現有圖像的圖紙上,如果您嘗試將圖像添加到已有一些圖像的圖紙上,它將不起作用 – Gagravarr