本文介绍了使用 POI 的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 poi 3.7 ,上传文件是 .xlsx
I'm using poi 3.7 , upload the file is .xlsx
控制台显示:
org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:186)
at poi.POITest.ReadAndPrintExcelFile(POITest.java:15)
at poi.POITest.main(POITest.java:59)
Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:147)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:592)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:222)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
... 3 more
推荐答案
只需使用org.apache.poi.ss.usermodel.WorkbookFactory
而不是创建实例:new HSSFWorkbook() 或 new XSSFWorkbook().
Just use org.apache.poi.ss.usermodel.WorkbookFactory
instead of creating instances : new HSSFWorkbook() or new XSSFWorkbook().
Workbook exWorkBook = WorkbookFactory.create(excelInputStream);
这篇关于使用 POI 的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!