您的位置:首页 > 编程语言 > Java开发

java 操作word 使用POI3.7

2012-08-03 16:59 405 查看
public static void readWord2003(String filename) {
InputStream inputStream = null;
WordExtractor wordExtractor = null;
String word = null;
try {
inputStream = new FileInputStream(filename);
wordExtractor = new WordExtractor(inputStream);
word = wordExtractor.getText();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != inputStream) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println(word);
}

public static void readWord2007(String filename) {
OPCPackage opcPackage = null;
XWPFWordExtractor xwpfWordExtractor = null;
String word = null;
try {
opcPackage = POIXMLDocument.openPackage(filename);
xwpfWordExtractor = new XWPFWordExtractor(opcPackage);
word = xwpfWordExtractor.getText();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlException e) {
e.printStackTrace();
} catch (OpenXML4JException e) {
e.printStackTrace();
}
System.out.println(word);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: