: The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (eg HSSF instead of XSSF)
时间: 2023-07-19 20:27:45 浏览: 81
这个错误通常出现在使用 Apache POI 处理 Excel 文件时,因为 Apache POI 提供了两个不同的 API 用于处理 Excel 文件,即 HSSF 和 XSSF,分别对应 Excel 2003 和 Excel 2007 及以上版本。如果你在处理 Excel 文件时出现这个错误,说明你使用了错误的 API。你需要检查你的代码,确认你使用的是正确的 API。如果你的 Excel 文件是一个旧版本(即 Excel 2003 及以前版本),你需要使用 HSSF API 来处理它。如果你的 Excel 文件是一个新版本(即 Excel 2007 及以后版本),你需要使用 XSSF API 来处理它。
相关问题
The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML
"The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (e.g. HSSF instead of XSSF)"这个错误是由于使用了错误的POI部分处理给定的数据格式引起的。您需要调用POI的另一个部分来处理数据。具体来说,如果您处理的是doc文件,应该使用HWPFDocument来读取;如果您处理的是xls文件,应该使用HSSFWorkbook来读取。如果您处理的是docx文件,应该使用XWPFDocument来读取;如果您处理的是xlsx文件,应该使用XSSFWorkbook来读取。请根据您所处理的文件类型选择正确的POI部分进行处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [The supplied data appears to be in the OLE2 Format.](https://blog.csdn.net/qq_40014707/article/details/114318042)[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: 50%"]
- *3* [POI OLE2NotOfficeXmlFileException:The supplied data appears to be in the OLE2 Format问题解决](https://blog.csdn.net/qq_38974638/article/details/116210340)[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: 50%"]
[ .reference_list ]
The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) 是什么原因
这个错误通常是因为你尝试读取的 Word 文档不是 OOXML 格式(.docx),而是 OLE2 格式(.doc)。Apache POI 库中的 `XWPFDocument` 类只能处理 OOXML 格式的文档。
如果你要读取 OLE2 格式的 Word 文档,你可以使用 `HWPFDocument` 类。这是 Apache POI 库中处理旧版 Word 文档的类。以下是一个读取 OLE2 格式文档的示例代码:
```java
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import java.io.FileInputStream;
import java.io.IOException;
public class WordReader {
public static void main(String[] args) {
try {
FileInputStream file = new FileInputStream("path/to/your/doc/file.doc");
HWPFDocument doc = new HWPFDocument(file);
WordExtractor extractor = new WordExtractor(doc);
String text = extractor.getText();
System.out.println(text);
doc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
请注意,在使用 `HWPFDocument` 时,你需要将文档的扩展名更改为 `.doc`,并且使用 `WordExtractor` 来提取文档的内容。
希望这次能够解决你的问题!如果还有其他疑问,请随时问我。