You need to call a different part of POI to process this data (eg XSSF instead of HSSF)的解决方法

Posted 秋9

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了You need to call a different part of POI to process this data (eg XSSF instead of HSSF)的解决方法相关的知识,希望对你有一定的参考价值。

【现象】

Exception in thread "main" 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)
    at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)
    at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303)

【解决方法】

FileInputStream inps = new FileInputStream(System.getProperty("user.dir")+"\\\\运费.xlsx");
//读取工作簿
HSSFWorkbook workBook = new HSSFWorkbook(inps);
//读取工作表
HSSFSheet sheet = workBook.getSheetAt(0);

修改为:

 

FileInputStream inps = new FileInputStream(System.getProperty("user.dir")+"\\\\运费.xlsx");
//读取工作簿
XSSFWorkbook workBook = new XSSFWorkbook(inps);
//读取工作表
XSSFSheet sheet = workBook.getSheetAt(0);

以上是关于You need to call a different part of POI to process this data (eg XSSF instead of HSSF)的解决方法的主要内容,如果未能解决你的问题,请参考以下文章

Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest

SpringBoot Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration

Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest

What skills you need to become a full stack java developer?

What makes an inferred latch? how To avoid creating inferred latches? when do you know you need lat

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Context