为了从单词文档中提取文本,XWPFWordExtractor类提供了一种getText()方法。此方法从文档中获取所有文本。
这是一种有用的方法,可用于Java程序中以读取数据。
让无涯教程看一个示例,在该示例中将从doc文件中提取文本。
链接:https://www.learnfk.comhttps://www.learnfk.com/apache-poi-word/apache-poi-word-extract-text.html
来源:LearnFk无涯教程网
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("Learnfk.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.
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕