org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
时间: 2023-07-19 22:18:15 浏览: 37
这个错误是因为你正在使用 HSSF API 处理一个 Office 2007+ XML 文件,而 HSSF API 是用于处理 OLE2 Office 文件格式的。因此,你需要使用 XSSF API 来处理 Office 2007+ XML 文件格式。你可以尝试使用 XSSFWorkbook 来代替 HSSFWorkbook 来读取你的文件,这样就可以避免这个错误。例如,你可以使用以下代码来读取 Office 2007+ XML 文件:
```
FileInputStream file = new FileInputStream(new File("yourfile.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
```
另外,如果你需要同时处理多种 Office 文件格式,你可以使用 Apache POI 中的工厂类来创建不同的 Workbook 对象,例如:
```
Workbook workbook = WorkbookFactory.create(new File("yourfile.xlsx"));
```
这样可以自动识别文件格式并创建相应的 Workbook 对象。
相关问题
org.apache.poi.poifs.filesystem.officexmlfileexception: the supplied data appears to be in the office 2007+ xml. you are calling the part of poi that deals with ole2 office documents. you need to call a different part of poi to process this data (eg xssf instead of hssf)
这个错误提示是说你提供的数据似乎是Office 2007+ XML格式的,而你正在调用POI处理OLE2 Office文档的部分。你需要调用POI的另一个部分来处理这个数据(例如使用XSSF而不是HSSF)。
The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals
"The supplied data appears to be in the Office 2007 XML. You are calling the part of POI that deals with OLE2 Office Documents." 这个错误是由于使用了错误的POI解析类导致的。POI是一个用于操作Microsoft Office文件的开源库,分为HSSF和XSSF两部分,分别用于处理旧版(xls)和新版(xlsx)的Excel文件。当你使用HSSFWorkbook来解析xlsx文件时,就会出现这个错误。正确的处理方法是使用XSSFWorkbook来解析xlsx文件。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [NPOIDemo.zip](https://download.csdn.net/download/qq_23663693/12370014)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [java处理excel库,poi-bin-4.1.0-20190412](https://download.csdn.net/download/cp62/11156022)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals](https://blog.csdn.net/weixin_46205984/article/details/122255403)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]