I wrote some code to replace variables in docx tamplate file header.
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()
is a Map has contains the variables and values.
When I running the unit test the replace is corectly fine but I use this in my web application on Tomee Plume the variables does not replaced.
For example the variable is: ${TOCHANGE}
it looks like this after change TOCHANGE.
Docx4j version is: 3.3.6
Please help me to resolve this issue.
It won't work if your KEY is split across separate runs in your docx.