本文概述
- Apache POI提取文本示例
【apache poi word提取文本】这是一种有用的方法,可以在Java程序中用于读取数据。
让我们看一个示例,其中我们从doc文件中提取文本。
Apache POI提取文本示例
package poiexample;
import java.io.FileInputStream;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
public class ReadingText {
public static void main(String[] args) {
try(FileInputStream fis = new FileInputStream("srcmini.docx")) {
XWPFDocument file= new XWPFDocument(OPCPackage.open(fis));
XWPFWordExtractor ext = new XWPFWordExtractor(file);
System.out.println(ext.getText());
}catch(Exception e) {
System.out.println(e);
}
}
}
输入:
文章图片
输出:
Apache POI (Poor Obfuscation Implementation) is a project design and developed by
Apache Software Foundation. It is a collection of pure Java libraries, used to read
and write Microsoft office files such as Word, PowerPoint etc.
推荐阅读
- apache poi word对齐
- apache poi word提取段落
- apache poi和powerpoint
- apache poi创建ms word文档
- apache poi microsoft word文档
- apache poi的注释
- apache poi样式化形状
- apache poi重写
- apache poi读取单元内容