2012-11-07 215 views
0

我試圖獲取Doc/Docx文本內容。看來,Apache的POI這樣做。我在pom.xml中包含了依賴關係。我試過很多這樣的代碼示例:apache POI打開docx文件失敗

File docFile1=new File("c:\\document1.docx") 
    FileInputStream inputStream = new FileInputStream(docFile1); 
    XWPFDocument docIn = new XWPFDocument(inputStream); 
    XWPFWordExtractor extractor = new XWPFWordExtractor(docIn); 
    String docText = extractor.getText(); 

這行代碼不能編譯。 eclipse錯誤在第3行(構造函數XWPFDocument(FileInputStream)未定義)。許多Web資源,這應該工作,但它沒有。有任何想法嗎 ?

回答

0

對於有同樣問題的人。包括最後一個POI版本可以解決問題,在寫入時它是3.7。

+1

請驗證。在[poi網頁](http://poi.apache.org/download.html)上說明*最新的穩定版本是Apache POI 3.8 *。 3.8是我使用的版本,檔案的日期是20120326. – Jarekczek

+0

你是對的。日Thnx –