下面是我程序里用的,不过只是解析文本,你可以参考下:
import java.io.FileInputStream
import org.apache.poi.hwpf.extractor.WordExtractor
import org.apache.poi.xwpf.extractor.XWPFWordExtractor
import org.apache.poi.xwpf.usermodel.XWPFDocument
/**
* 对MS office文档的处理
* @author caoshen
*
*/
public class OfficeUtils {
/**
* 获得WORD文档所有的内容
* @param filePath
* @return
*/
public static String getWordContent(String filePath){
String content = ""
FileInputStream fis
try {
fis = new FileInputStream(filePath)
WordExtractor we = new WordExtractor(fis)
content = we.getText()
} catch (Exception e) {
try {
fis = new FileInputStream(filePath)
XWPFWordExtractor oleTextExtractor = new XWPFWordExtractor(new XWPFDocument(fis))
content = oleTextExtractor.getText()
} catch (Exception e1) {
e1.printStackTrace()
}
}
return content
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)