我試圖查看Word文件在我的編輯窗格 我想這些線路如何使用Poi閱讀doc文件?
import java.awt.Dimension;
import java.awt.GridLayout;
import java.io.File;
import java.io.FileInputStream;
import javax.swing.JEditorPane;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class editorpane extends JEditorPane
{
public editorpane(File file)
{
try
{
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
HWPFDocument hwpfd = new HWPFDocument(fis);
WordExtractor we = new WordExtractor(hwpfd);
String[] array = we.getParagraphText();
for (int i = 0; i < array.length; i++)
{
this.setPage(array[i]);
}
} catch (Exception e)
{
e.printStackTrace();
}
,但給我
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)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:106)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:174)
at frame1.editorpane.<init>(editorpane.java:24)
在這一行
HWPFDocument hwpfd = new HWPFDocument(fis);
我該怎麼解決??
旁邊我不知道對這些行
for (int i = 0; i < array.length; i++)
{
this.setPage(array[i]);
}
我可以讓他們證實?
你看了錯誤信息?您是否嘗試使用XSSF而不是HSSF? – 2016-01-21 13:23:37
我無法找到什麼是xssf或在哪裏被替換 –
嘗試XWPFDocument類。文檔的類型是什麼?它是一個doc或docx文件嗎? – 2016-01-21 13:40:21