java之POI提取word文本+表格

Shaka 5月前 ⋅ 127 阅读

 

作者:knqi007
来源:CSDN
原文:https://blog.csdn.net/knqi007/article/details/73899854

public String readWord(String path) {
String buffer = "";
try {
if (path.endsWith(".doc")) {
InputStream is = new FileInputStream(new File(path));
WordExtractor ex = new WordExtractor(is);
buffer = ex.getText();
ex.close();
} else if (path.endsWith("docx")) {
OPCPackage opcPackage = POIXMLDocument.openPackage(path);
POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
buffer = extractor.getText();
extractor.close();
} else {
System.out.println("此文件不是word文件!");
}

} catch (Exception e) {
e.printStackTrace();
}

return buffer;
}

---------------------


注意:本文归作者所有,未经作者允许,不得转载

全部评论: 0

    我有话说: