如何提取使用了Apache POI 3.5新OOXML的支持DOCX文件纯文本? [英] How to extract plain text from a DOCX file using the new OOXML support in Apache POI 3.5?

查看:247
本文介绍了如何提取使用了Apache POI 3.5新OOXML的支持DOCX文件纯文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2009年9月28日,的Apache POI项目发布3.5版从而正式支持在Office 2007中引入的OOXML格式,如DOCX和XLSX。

On September 28, 2009 the Apache POI project released version 3.5 which officially supports the OOXML formats introduced in Office 2007, like DOCX and XLSX.

请提取纯文本的DOCX文件的内容,忽略任何样式或格式提供code样本。

Please provide a code sample for extracting a DOCX file's content in plain text, ignoring any styles or formatting.

我问这个,因为我一直无法找到任何Apache POI例子覆盖新的OOXML的支持。

I am asking this because I have been unable to find any Apache POI examples covering the new OOXML support.

推荐答案

这为我工作。请确保您添加需要的jar(升级的XMLBeans等)

This worked for me. Make sure you add the required jars (upgrade xmlbeans, etc.)

public String extractText(InputStream in) throws Exception {
	XWPFDocument doc = new XWPFDocument(in);
	XWPFWordExtractor ex = new XWPFWordExtractor(doc);
	String text = ex.getText();
	return text;
}

这篇关于如何提取使用了Apache POI 3.5新OOXML的支持DOCX文件纯文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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