关于使用POI导出时excel版本问题的bug解决
来源:互联网 发布:网络理财软件排行榜 编辑:程序博客网 时间:2024/06/11 12:31
使用POI文档。实例化对象时代码如下:
Workbook wb = new HSSFWorkbook(new FileInputStream(new File("D:\\tFACTORY.xls")));
但是D盘的excel文件格式是.xlsx格式的,导致出现了如下的错误:
HTTP Status 500 - Request processing failed; nested exception is org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
type Exception report
message Request processing failed; nested exception is org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)javax.servlet.http.HttpServlet.service(HttpServlet.java:650)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)javax.servlet.http.HttpServlet.service(HttpServlet.java:731)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322)org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303)org.jk.controller.cargo.contract.OutProductController.print(OutProductController.java:50)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)java.lang.reflect.Method.invoke(Unknown Source)org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)javax.servlet.http.HttpServlet.service(HttpServlet.java:650)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)javax.servlet.http.HttpServlet.service(HttpServlet.java:731)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)解决的办法如下:使用正则表达式,判断实例化对象时候进行一个选择
String fileName = "D:\\tFACTORY.xlsx";
if (fileName.matches("^.+\\.(?i)((xls)|(xlsx))$")) {
boolean is03Excel = fileName.matches("^.+\\.(?i)(xls)$");
FileInputStream inputStream = new FileInputStream(fileName);
Workbook wb = is03Excel ? new HSSFWorkbook(inputStream) : new XSSFWorkbook(inputStream);
。。。。。。
}
- 关于使用POI导出时excel版本问题的bug解决
- 使用poi导出excel后,关于出现#NAME? 的问题,已解决
- excel 导出,关于POI的使用经验
- 使用poi做excel导出时解决以文本格式存储的数字问题
- 使用poi做excel导出时解决以文本格式存储的数字问题
- 使用poi做excel导出时解决以文本格式存储的数字问题
- 关于poi导出excel时的各种注意问题
- 关于struts2中使用POI的方式导出EXCEL文件时的国际化问题
- POI 3.8版本导出excel问题
- poi工具导出excel乱码问题的解决过程
- 使用POI进行Excel导入时解决的一些问题
- 关于java poi导入导出excel的包冲突问题
- 使用poi低版本(poi-3.0.1)导出Excel整理
- 关于使用POI实现excel导出
- 使用poi导出大量数据到excel遇到的问题
- 关于poi导出Excel
- 关于产品财务报表导入版本问题的解决方案低版本高版本通用 (POI导入导出excel报org.apache.xmlbeans.XmlOptions.setLoadEntityBytesLimit错误)
- 使用Apache POI导出Excel数据有BUG
- Spring:IOC—控制反转(4)
- Oracle11g密码过期
- Java se之静态代码块、代码块、构造函数执行顺序问题
- Elasticsearch(一) 基本概念
- 从UGUI开始优化手游性能问题
- 关于使用POI导出时excel版本问题的bug解决
- 百度bae部署java项目
- shiro 中的filterChainDefinitions详解
- ScheduledExecutorService定时周期执行指定的任务
- CentOS7 安装tomcat
- Qt之设置QWidget背景色(QStyleOption->drawPrimitive(QStyle::PE_Widget)方法比较有趣)
- Android监测手机网络状态变化的广播
- 对 Linux 新手非常有用的 20 个命令
- Cgroups