用 Java 将 Microsoft Word 文档读取为纯文本(DOC、DOCX) [英] Read Microsoft Word Documents into Plain Text (DOC, DOCX) in Java

查看:51
本文介绍了用 Java 将 Microsoft Word 文档读取为纯文本(DOC、DOCX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找 Java 中的一些东西,以便在 Word 文档中阅读以处理它们的文本.我所需要的只是文本,没有什么花哨的东西.我知道 Apache POI,但它现在不包括对 DOCX 的支持,还有什么吗?

I'm looking for something in Java to read in Word documents to process their text.. all I need is there text, nothing fancy. I know about Apache POI, however it doesn't include support for DOCX right now, anything out there?

推荐答案

如果您不需要格式化信息、图像和所有其他花哨的东西,那么工作就容易多了.只需 5 到 10 行代码即可.

If you don't require formatting information, images and all other fancy stuff, then the job is lot easier. Just some 5 to 10 lines of code will do.

  1. 将 DOCX 视为 zip 文件.它由一堆文件组成,其中包括document.xml".使用 ZipInputStream 并单独提取该文件.(您可以使用您最喜欢的 zip 实用程序并打开 docx 并亲自查看!)
  2. 使用 SAX 解析器并读取节点 body/p/r/t 之间的内容 - 瞧,您得到了文本!

仅当您需要纯文本时才适用.

这篇关于用 Java 将 Microsoft Word 文档读取为纯文本(DOC、DOCX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆