星空网 > 软件开发 > Java

java解析excel2003和excel2007:The supplied data appears to be in the office 2007+XML Polonly supports OLE2 office documents

上传excel解析存到数据库时报:

org.apache.poi.poifs.filesystem.Office

The supplied data appears to be in the Office 2007+

You need to call a different part of POI to process this data (eg XSSF instead of HSSF)

该错误意思是说,文件中的数据是用Office2007+

比如使用XSSF来代替HSSF。

断点跟踪到:new HSSFWorkbook(file.getInputStream)出错,在网上找了很多方法,都不行,最后在一个犄角旮旯里找到如下方法

Workbook wb=WorkbookFactory.create(file.getInputStream); 

 

用的maven依赖(版本号最好一致,否则容易出错)

<dependency>  <groupId>org.apache.poi</groupId>  <artifactId>poi</artifactId>  <version>3.14-beta1</version></dependency><dependency>  <groupId>org.apache.poi</groupId>    <artifactId>poi-oo</artifactId>    <version>3.14-beta1</version> </dependency> <dependency>   <groupId>org.apache.poi</groupId>   <artifactId>poi-oo</artifactId>   <version>3.14-beta1</version> </dependency> 

 

原文网址::http://www.itnose.net/detail/6144353.html

 

springmvc上传excel解析存到数据库原文博客:http://blog.csdn.net/jinwufeiyang/article/details/52216218

將原博客以下方法稍作了修改。

public List<Customer> getExcelInfo(String fileName, MultipartFile Mfile) {  List<Customer> customerList = new ArrayList<Customer>();  try {    // 验证文件名是否合格    if (!validateExcel(fileName)) {      return null;    }  } catch (Exception e) {    e.printStackTrace();  }  // 根据文件名判断文件是2003版本还是2007版本  boolean isExcel2003 = true;  if (WDWUtil.isExcel2007(fileName)) {    isExcel2003 = false;  }  try {    customerList = getExcelInfo(Mfile.getInputStream(), isExcel2003);  } catch (IOException e) {    e.printStackTrace();  }  return customerList;}

 




原标题:java解析excel2003和excel2007:The supplied data appears to be in the office 2007+XML Polonly supports OLE2 office documents

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流