简体   繁体   English

使用docx4j在同一文档中用新数据重新填充docx模板

[英]refill a docx template with new data in the same document using docx4j

i am trying to fill a docx template with different data but i can not make any progress. 我试图用不同的数据填充docx模板,但是我无法取得任何进展。 I have tried two approaches. 我尝试了两种方法。 First using only java code and second one using content control binding. 第一个仅使用Java代码,第二个仅使用内容控件绑定。 For the first approach i used this tutorial http://www.smartjava.org/content/create-complex-word-docx-documents-programatically-docx4j and for the second one this one https://github.com/plutext/docx4j/blob/07c0b68512cbb3eef52ae51c3f597a7be4428232/src/samples/docx4j/org/docx4j/samples/ContentControlBindingExtensions.java . 对于第一种方法,我使用了本教程http://www.smartjava.org/content/create-complex-word-docx-documents-programatically-docx4j ,对于第二种方法,此教程为https://github.com/plutext/ docx4j / blob / 07c0b68512cbb3eef52ae51c3f597a7be4428232 / src / samples / docx4j / org / docx4j / samples / ContentControlBindingExtensions.java The problem is I do not know how to reuse the same template and just fill it with other datasets? 问题是我不知道如何重用相同的模板,而仅用其他数据集填充它? Should I use xsl in order to make the logic? 我是否应该使用xsl来制定逻辑? The picture below illustrates my goal, where first and second table are meant to be in the same document. 下图说明了我的目标,第一张表和第二张表应位于同一文档中。

重新填充相同的模板

Each time you do the binding, you create a new instance docx. 每次进行绑定时,都会创建一个新的实例docx。

If you want the contents of multiple instance documents concatenated in a single docx, you'll have to do that as a separate step. 如果要将多个实例文档的内容合并到一个docx中,则必须作为一个单独的步骤进行。

If the contents is simple text & tables, you can just copy the contents list. 如果内容是简单的文本和表格,则只需复制内容列表即可。

More likely, it contains relationship references etc, in which case you need to handle those. 它更可能包含关系引用等,在这种情况下,您需要处理这些引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM