我已经使用POI和嵌入图像创建了一个excel文件。它的工作正常。当我将它嵌入到web应用程序中并部署在apache tomcat服务器上时。图像未显示在Excel文件中。以下是代码,
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet1");
InputStream logo_image = new FileInputStream("C:\\Logo.jpg");
byte[] bytes = IOUtils.toByteArray(logo_image);
int picIndex = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
logo_image.close();
HSSFPatriarch drawing = sheet.createDrawingPatriarch();
ClientAnchor my_anchor = new HSSFClientAnchor();
my_anchor.setCol1(0);
my_anchor.setRow1(1);
HSSFPicture my_picture = drawing.createPicture(my_anchor, picIndex);
my_picture.resize(.4);
FileOutputStream out = new FileOutputStream(new File( "C:\\image_example1.xls"));
workbook.write(out);
out.close();
注意:它正在处理1个tomcat实例,但是在另一台机器上正在生成excel但是没有嵌入图像。
我也试过添加my_anchor.setCol12(2);my_anchor.setRow2(0);
,但没有帮助。