我有word文档(它是基于docx和xml的),我希望找到一个表并以编程方式填充它。我正在使用Apache,XWPF API。
是否有一种通过它们的id?访问XWPF元素的方法?
如何在XWPF元素之间创建唯一性,然后使用java修改?
谢谢
发布于 2017-07-06 13:26:35
我实现的是一个查找替换特性(from here);
在我的模板docx文件中,我使用"id like text“、__heading1__、__subjectname__,然后用下面的代码替换它们。对于tables @的解决方案可能是合适的。
private void findReplace(String a, String b, CustomXWPFDocument document){
for (XWPFParagraph p : document.getParagraphs()) {
List<XWPFRun> runs = p.getRuns();
if (runs != null) {
for (XWPFRun r : runs) {
String text = r.getText(0);
if (text != null && text.contains(a)) {
text = text.replace(a, b);
r.setText(text, 0);
}
}
}
}
}https://stackoverflow.com/questions/44885092
复制相似问题