本文介绍了org.apache.poi.POIXMLException 目前不支持严格的 OOXML,请参阅错误 #57699的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用java解析一个Excel文件,所以我使用的是apache poi库,这里你是maven依赖:

<groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.14</version></依赖>

这将包括一系列依赖:

poi-ooxml-3.14.jarpoi-3.14.jarcommons-codec-1.10.jarpoi-ooxml-schemas-3.14.jarxmlbeans-2.6.0.jarstax-api-1.0.1.jarCurvesapi-1.03.jar

当我尝试使用此代码读取 Office 365 Excel 文件 (.xslx) 时:

import org.apache.poi.ss.usermodel.Cell;导入 org.apache.poi.ss.usermodel.Row;导入 org.apache.poi.ss.usermodel.Sheet;导入 org.apache.poi.ss.usermodel.Workbook;导入 org.apache.poi.xssf.usermodel.XSSFWorkbook;公共类 ExcelConverter {public static void main(String[] args) 抛出异常{String excelFilePath = "C:/temp/Book1.xlsx";File myFile = new File(excelFilePath);System.out.println("文件存在:" + myFile.exists());FileInputStream inputStream = new FileInputStream(myFile);工作簿工作簿 = new XSSFWorkbook(inputStream);}}

我收到以下控制台消息:

文件存在:true线程main"org.apache.poi.POIXMLException 中的异常:当前不支持严格的 OOXML,请参阅错误 #57699在 org.apache.poi.POIXMLDocumentPart.getPartFromOPCPackage(POIXMLDocumentPart.java:679)在 org.apache.poi.POIXMLDocumentPart.(POIXMLDocumentPart.java:122)在 org.apache.poi.POIXMLDocumentPart.(POIXMLDocumentPart.java:115)在 org.apache.poi.POIXMLDocument.(POIXMLDocument.java:61)在 org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:273)在 org.myCompany.excel.ExcelConverter.main(ExcelConverter.java:25)

你知道我该怎么做才能解决这个问题吗?提前致谢

解决方案

除了不要以严格的 OOXML"格式保存电子表格之外,目前似乎没有任何简单的解决方案.

例如在Excel中使用

另存为 -->Excel 工作簿 (.xlsx)"

代替

另存为 -->严格的 Open XML 电子表格 (.xlsx)"

你知道为什么 Excel Worksheet 和这种格式的文件扩展名相同吗?

这将是只有 Microsoft 才能回答的问题.但我猜工程师(或他们的管理层)没有预料应用软件有必要做出区分.

我接受文件作为输入,然后根据扩展名处理它们.如果没有 try-catch,我怎么知道?

没有什么可以让您使用当前一代 POI 处理文档.

我想您可以编写一些代码来读取文件并在将文件传递给 POI 之前查找严格的 OOXML"格式 的签名,但没有多大意义.您将编写一堆额外的代码,以便您可以用其他逻辑替换 try-catch.

I'd like to parse an Excel file with java, so I'm using apache poi libraries, here you are the maven dependencies:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.14</version>
</dependency>

This will include a series of dependencies:

poi-ooxml-3.14.jar
poi-3.14.jar
commons-codec-1.10.jar
poi-ooxml-schemas-3.14.jar
xmlbeans-2.6.0.jar
stax-api-1.0.1.jar
curvesapi-1.03.jar

When I try to read an Office 365 Excel file (.xslx) with this code:

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelConverter {

    public static void main(String[] args) throws Exception{
        String excelFilePath = "C:/temp/Book1.xlsx";
        File myFile = new File(excelFilePath);
        System.out.println("File exists: " + myFile.exists());
        FileInputStream inputStream = new FileInputStream(myFile);

        Workbook workbook = new XSSFWorkbook(inputStream);
   }
}

I got the following console message:

File exists: true
Exception in thread "main" org.apache.poi.POIXMLException: Strict OOXML isn't currently supported, please see bug #57699
    at org.apache.poi.POIXMLDocumentPart.getPartFromOPCPackage(POIXMLDocumentPart.java:679)
    at org.apache.poi.POIXMLDocumentPart.<init>(POIXMLDocumentPart.java:122)
    at org.apache.poi.POIXMLDocumentPart.<init>(POIXMLDocumentPart.java:115)
    at org.apache.poi.POIXMLDocument.<init>(POIXMLDocument.java:61)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:273)
    at org.myCompany.excel.ExcelConverter.main(ExcelConverter.java:25)

Do you know what can I do to solve the issue?Thanks in advance

解决方案

There doesn't currently appear to be any simple solution other than "Don't save your spreadsheet in "strict OOXML" format."

For example, in Excel use

Save As --> "Excel Workbook (.xlsx)"

instead of

Save As --> "Strict Open XML Spreadsheet (.xlsx)"


That would be something that only Microsoft can answer. But I guess that the engineers (or their management) did not anticipate that it would be necessary for application software to make the distinction.

There is nothing that will let you process the document with current generation POI.

I guess you could code something to read the file and look for the signature for "strict OOXML" format before passing the file to POI, but there's not much point. You would be writing a stack of extra code just so that you can replace the try-catch with other logic.


这篇关于org.apache.poi.POIXMLException 目前不支持严格的 OOXML,请参阅错误 #57699的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:43