且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取异常(org.apache.poi.openxml4j.exception - 没有内容类型[M1.13])阅读使用Apache POI XLSX文件时?

更新时间:2021-12-25 14:55:03

该错误是告诉你,POI找不到OOXML文件的核心部分,在这种情况下,内容类型的一部分​​。您的文件是不是有效的OOXML文件,更何况是一个有效的.xlsx文件。这虽然是一个有效的zip文件,否则,你已经得到了以前的错误

The error is telling you that POI couldn't find a core part of the OOXML file, in this case the content types part. Your file isn't a valid OOXML file, let alone a valid .xlsx file. It is a valid zip file though, otherwise you'd have got an earlier error

可以将Excel真的加载此文件?我希望它也不能,因为异常被赋予POI常规.zip文件最常用的触发!我怀疑你的文件是无效的,因此例外

Can Excel really load this file? I'd expect it wouldn't be able to, as the exception is most commonly triggered by giving POI a regular .zip file! I suspect your file isn't valid, hence the exception

更新:在Apache的POI 3.15(从Beta 1起),有这个问题的比较常见的原因更有益的一套异常的消息。现在,您会在这种情况下获得更多的描述性的异常,如: ODFNotOfficeXmlFileException 和 OLE2NotOfficeXmlFileException 。这种原始形式应该只会出现,如果真的POI有没有线索,你已经给它什么,但知道它的破碎或无效的。

Update: In Apache POI 3.15 (from beta 1 onwards), there's a more helpful set of Exception messages for the more common causes of this problem. You'll now get more descriptive exceptions in this case, eg ODFNotOfficeXmlFileException and OLE2NotOfficeXmlFileException. This raw form should only ever show up if POI really has no clue what you've given it but knows it's broken or invalid.