0
我正在使用Apache POI与使用java的docx文档一起工作。原理很简单:将docx复制到另一个末尾
- 我有一个基本模板,显示数据(文本,标题和表格)
- 我有,将填补该模板
- 我需要产生最终的文件,将数据包含为每个数据行重复的模板
我已成功加载模板文档,并且还创建了最终的文档对象,其中不包含任何内容(来自包含我想要的样式的空白文档,放松他们)。我可以通过浏览段落和表格来更改模板中的数据字段,但我不能做的是将已更改的内容复制到最终的文档中。
基本上,这是我所:
for (int i=0; i<10; i++) {
finalDoc.removeBodyElement(i);
}
for (int i=0; i<10; i++) {
//EditableDocX is a subclass of XWPFDocument, for purpose of my project
EditableDocX document = new EditableDocX("template.docx");
replacementMap.put("[field1]", "Content1_"+i);
replacementMap.put("[field2]", "Content2_"+i);
document.replaceWithMap(replacementMap); //I've have this working
finalDoc.addContentOfDoc(document); //I don't have this working :(
}
finalDoc.saveFile("result.docx");
有没有办法给document
对象的内容复制到finalDoc
对象的结束? (有段落和表格,带样式)