当前位置: 首页 > news >正文

java读取word文档内容

首先在pom文件引入依赖:

<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.0.0</version>
</dependency>
<dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.0.0</version>
</dependency>

然后写一个测试类:

public class FileTest {public static void main(String[] args) throws IOException {File file = new File("C:\\Users\\cs\\Desktop\\test.docx");FileInputStream fis = null;XWPFDocument document = null;XWPFWordExtractor extractor = null;fis = new FileInputStream(file);document = new XWPFDocument(fis);extractor = new XWPFWordExtractor(document);System.out.println(extractor.getText());}
}

 

其中XWPFDocument、XWPFWordExtractor是其依赖中的方法,运行代码,结果如下:

 

http://www.lryc.cn/news/67950.html

相关文章:

  • 使用Process Monitor排查因dll库被锁定导致C++程序启动报“0xc0000022”错误问题
  • Unity UI -- (1)概览
  • 玩转 LLMs 之基础设施「利刃出鞘」
  • WPF MaterialDesign 初学项目实战(1)首页搭建
  • 【纳什博弈、ADMM】基于纳什博弈和交替方向乘子法的多微网主体能源共享研究(Matlab代码实现)
  • 每日学术速递5.8
  • ChatGPT时代:我们可能站到了自然语言编程的大门口
  • 关于不同处理器的函数调用规则
  • Rust Wasm Linux开发环境搭建
  • 【项目设计】 负载均衡在线OJ系统
  • 【服务器】无公网IP,异地远程连接威联通NAS
  • 在中国,年收入20W是什么水平?答案扎心了(文末附最新招聘)
  • navicat连接oracle报错 ORA-28547
  • 量化指标WR:弱的确是弱,但是老Q会魔改啊!
  • 生物信息学知识点
  • 14.贪心算法
  • 你知道营销人为什么要讲洞察吗?
  • Neovim-配置教程
  • Windows管理内存的3种方式——堆、虚拟内存、共享内存
  • PCM/FM解调原理与Matlab算法仿真
  • 我的『1024』创作纪念日
  • Python ---> 衍生的数据技术
  • 【27】linux进阶——rpm软件包的管理
  • HTTP第六讲——键入网址再按下回车,后面究竟发生了什么?
  • layui目录和项目引入
  • Ubuntu22.04 将EFI启动分区迁移到另一块硬盘
  • 只要学会这些AI工具,一个人就是一家营销咨询公司
  • [离散数学] 函数
  • 好家伙,又一份牛逼笔记面世了...
  • 基于nodejs+vue3 的高仿网易云音乐