Excel导出打印失败报错 (eg HSSF instead of XSSF)

错误信息:

java.lang.RuntimeException: org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (eg HSSF instead of XSSF) 

 

原因是因为:

InputStream inputStream = session.getServletContext().getResourceAsStream("make/xlsprint/tOUTPRODUCT.xlsx");
Workbook workbook = new XSSFWorkbook(inputStream),XSSF操作的是Excel2007以上的版本,对应文件的后缀名是xlsx
Workbook workbook = new HSSFWorkbook(inputStream),HSSF操作的是Excel2003以前的版本,对应的文件后缀名是xls

检查输入流导入的文件的Excel的版本,使用对应的POI操作
上一篇:java – 使用Apache POI重新计算电子表格中的公式


下一篇:fabric源码相关