我有一个表,我需要向其中添加多行,而不是您在图像中看到的变量。我正在使用 docx4j。
我改变这样的变量:
HashMap mappings = new HashMap();
VariablePrepare.prepare(template);
mappings.put("example", "example");
template.getMainDocumentPart().variableReplace(mappings);
Run Code Online (Sandbox Code Playgroud)
VariableReplace 不适用于重复数据。
您可以改用 OpenDoPE 内容控件数据绑定:将重复内容控件包裹在表行周围。
https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/model/datastorage/migration/FromVariableReplacement.java可能有助于从 VariableReplace 迁移到 OpenDoPE。