我正在使用 Poi Apache 生成一个 excel 文件,我必须将图片添加到我的文件中,但问题是当我将项目导出到 Runnable Jar 时,它不起作用。
InputStream is = ExcelTools.class.getClassLoader().getResourceAsStream( "./ensao/pfa/opendelib/resources/LogoOpen.jpg" );
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
Drawing drawing = sheet.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(40, 10, 65, 20,
(short) 0, 0, (short) 0, 0);
anchor.setAnchorType(1);
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize();
问题是从这一行发起的:
byte[] bytes = IOUtils.toByteArray(is);