Java 获取 POI 错误:org.apache.poi.POIXMLException:org.apache.poi.openxml4j.exceptions

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19533892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:06:44  来源:igfitidea点击:

Getting error for POI : org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions

javaselenium-webdriverapache-poidata-driven

提问by pratik

I have 2 excel files, calling from TestSuite.xlsx the other TestCase.xlsx file. My 1st excel file is running successfully but when I run for other excel file getting the following error.

我有 2 个 excel 文件,从 TestSuite.xlsx 调用另一个 TestCase.xlsx 文件。我的第一个 excel 文件运行成功,但是当我运行其他 excel 文件时出现以下错误。

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:204)
at com.iopendr.xls.read.Xls_Reader.<init>(Xls_Reader.java:32)
at com.iopendr.test.DriverScript.start(DriverScript.java:96)
at com.iopendr.test.DriverScript.main(DriverScript.java:60)
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:178)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:662)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:269)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
... 4 more

回答by Satish Reddy

You need to see .xlsx file at column number 13 and verify in your code, I think it takes the another column value instead of 13th column value.

您需要在第 13 列查看 .xlsx 文件并在您的代码中进行验证,我认为它采用另一列值而不是第 13 列值。

回答by maniac787

Try this:

尝试这个:

Workbook workbook = new XSSFWorkbook(byteFile); //ERROR
Workbook workbook = WorkbookFactory.create(byteFile); //OK

回答by Tushar Banne

just open the excel sheet in MS Excel and save it in .xlsx format. then try to access it through the code.

只需在 MS Excel 中打开 Excel 表格并将其保存为 .xlsx 格式。然后尝试通过代码访问它。

This has worked for me.

这对我有用。