The supplied data appears to be in the OLE2 Format.
ThesupplieddataappearstobeintheOLE2Format.YouarecallingthepartofPOIthatdealswithOOXML(OfficeOpenXML)Documents.YouneedtocalladifferentpartofPOItoprocessthisdata(egHSSFinsteadofXSSF)在做Excel导入功能时,发现导入的文件
·
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后,再次导入,就不在报错了。
总结:
修改文件类型时最好使用另存为,避免出现版本问题。
更多推荐
活动日历
查看更多
直播时间 2025-02-26 16:00:00


直播时间 2025-01-08 16:30:00


直播时间 2024-12-11 16:30:00


直播时间 2024-11-27 16:30:00


直播时间 2024-11-21 16:30:00


目录
所有评论(0)