变量没有被替换
Variables did not replaced
我写了一些代码来替换 docx 模板文件头中的变量。
List<SectionWrapper> sectionWrappers = this.wordMLPackage.getDocumentModel().getSections();
for (SectionWrapper sw : sectionWrappers) {
HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
HeaderPart defaultHP = hfp.getDefaultHeader();
if (defaultHP != null) {
defaultHP.variableReplace(getVariablesForChange());
if (hfp.getFirstHeader() != null) {
hfp.getFirstHeader().variableReplace(getVariablesForChange());
}
}
}
getVariablesForChange()
是一个包含变量和值的Map。
当我 运行 单元测试时,替换完全没问题,但我在 Tomee Plume 上的 Web 应用程序中使用它时,变量没有被替换。
例如,变量是:${TOCHANGE}
更改 TOCHANGE 后看起来像这样。
Docx4j 版本为:3.3.6
请帮我解决这个问题。
如果您的 KEY 在您的 docx 中被分开运行,它将不起作用。
我写了一些代码来替换 docx 模板文件头中的变量。
List<SectionWrapper> sectionWrappers = this.wordMLPackage.getDocumentModel().getSections();
for (SectionWrapper sw : sectionWrappers) {
HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
HeaderPart defaultHP = hfp.getDefaultHeader();
if (defaultHP != null) {
defaultHP.variableReplace(getVariablesForChange());
if (hfp.getFirstHeader() != null) {
hfp.getFirstHeader().variableReplace(getVariablesForChange());
}
}
}
getVariablesForChange()
是一个包含变量和值的Map。
当我 运行 单元测试时,替换完全没问题,但我在 Tomee Plume 上的 Web 应用程序中使用它时,变量没有被替换。
例如,变量是:${TOCHANGE}
更改 TOCHANGE 后看起来像这样。
Docx4j 版本为:3.3.6
请帮我解决这个问题。
如果您的 KEY 在您的 docx 中被分开运行,它将不起作用。