如何从使用Apache POI MS Word文档的文本框的文本? [英] How to get text from textbox of MS word document using Apache POI?
本文介绍了如何从使用Apache POI MS Word文档的文本框的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得一个MS Word文档中写在文本框的信息。我使用Apache POI解析Word文档。
I want to get information written in Textbox in an MS word document. I am using Apache POI to parse word document.
目前,我通过遍历所有的段落对象,但本款列表不包含文本框,所以我缺少这个输出信息的信息。
Currently I am iterating through all the Paragraph objects but this Paragraph list does not contain information from TextBox so I am missing this information in output.
的例如的
paragraph in plain text
**<some information in text box>**
one more paragraph in plain text
我想提取:
<para>paragraph in plain text</para>
<text_box>some information in text box</text_box>
<para>one more paragraph in plain text</para>
什么我得到目前:
段落纯文本
在纯文本多了一个段落
任何人都知道如何从文本框中使用提取信息的Apache POI?
Anyone knows how to extract information from text box using Apache POI?
推荐答案
这工作对我来说,
private void printContentsOfTextBox(XWPFParagraph paragraph) {
XmlObject[] textBoxObjects = paragraph.getCTP().selectPath("
declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'
declare namespace wps='http://schemas.microsoft.com/office/word/2010/wordprocessingShape' .//*/wps:txbx/w:txbxContent");
for (int i =0; i < textBoxObjects.length; i++) {
XWPFParagraph embeddedPara = null;
try {
XmlObject[] paraObjects = textBoxObjects[i].
selectChildren(
new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "p"));
for (int j=0; j<paraObjects.length; j++) {
embeddedPara = new XWPFParagraph(
CTP.Factory.parse(paraObjects[j].xmlText()), paragraph.getBody());
//Here you have your paragraph;
System.out.println(embeddedPara.getText());
}
} catch (XmlException e) {
//handle
}
}
}
这篇关于如何从使用Apache POI MS Word文档的文本框的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文