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)
在做Excel导入功能时,发现导入的文件报错,代码中判断了文件类型:
// IO流读取文件
InputStream input = file.getInputStream();
//解析xls
HSSFWorkbook wb = new HSSFWorkbook(input);
//解析xlsx
XSSFWorkbook wbx = new XSSFWorkbook(input);
但是依旧报错:
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)
网上查询也都是版本问题。
后来反复测试,发现xls导入没问题,但是将文件后缀直接改成xlsx导入就会报错。
将文件另存为xlsx后,再次导入,就不在报错了。
总结:
修改文件类型时最好使用另存为,避免出现版本问题。