-1

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.

Alex Blasco
  • 793
  • 11
  • 22
Zaosz
  • 137
  • 1
  • 2
  • 11

1 Answers1

0

It won't work if your KEY is split across separate runs in your docx.

See https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/model/datastorage/migration/VariablePrepare.java

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Would you please give me more information about that? I don't see why working the same process in Unit test. What should I do to work that on Tomee plume? – Zaosz Nov 24 '17 at 12:04
  • post the document.xml content into the question, or the entire docx file somewhere so i can see it – JasonPlutext Nov 27 '17 at 11:10
  • You can download here: header1.xml: https://a.uguu.se/j6jMKl78riVG_header1.xml and document.xml : https://a.uguu.se/31sz6FU0jNYS_document.xml – Zaosz Nov 27 '17 at 12:06