且构网

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

为什么会得到这个异常:线程“主”中的异常org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException

更新时间:2021-07-03 17:17:58

您正在创建一个 XSSFWorkbook ,它仅适用于处理xlsx文件,即新的基于xml的Office格式。然而,您的文件扩展名(xls)表示这是较早的Microsoft Office(2003年我猜)的格式。为了修复错误,您需要将文件转换为xlsx格式,或者您需要使用 HSSFWorkbook

You're creating a XSSFWorkbook which is only suitable for working on xlsx files, i.e. the new xml based office format. Your file extension (xls) however suggests that this is the older Microsoft Office (2003 I guess) format. In order to fix the error you need to convert the file to xlsx format or you need to work with a HSSFWorkbook

您可以在这里找到有关HSSF的一些样本: https://poi.apache.org/spreadsheet/examples.html#hssf-only
一些例子关于XDDF可以在这里找到: https://poi.apache.org/spreadsheet /examples.html#xssf-only

You can find some samples concerning HSSF here: https://poi.apache.org/spreadsheet/examples.html#hssf-only Some examples concerning XDDF can be found here: https://poi.apache.org/spreadsheet/examples.html#xssf-only