Replace Variables in Header and Footer?
Posted:
Tue Nov 12, 2019 1:51 am
by hatdo45
I would like to replace placeholders also in headers and footers, i don't want to create these sections, but just use the variableReplace method.
But i could not find any example on how to use variableReplace for headers and footers.
Any code samples available?
Re: Replace Variables in Header and Footer?
Posted:
Tue Nov 12, 2019 8:04 pm
by adams
Hey,
you can do something like this:
- Code: Select all
for (SectionWrapper section : wordMLPackage.getDocumentModel().getSections() {
if (section.getHeaderFooterPolicy() != null) {
section.getHeaderFooterPolicy().getDefaultHeader().variableReplace(yourContent);
section.getHeaderFooterPolicy().getDefaultFooter().variableReplace(yourContent);
}
}
I recommend doing a null check on the default header and footer object, and an isEmpty check on the content of these (!section.getHeaderFooterPolicy().getDefaultHeader().getContent().isEmpty()).
Re: Replace Variables in Header and Footer?
Posted:
Tue Nov 12, 2019 11:42 pm
by hatdo45
Thank you very much, your code works!
Re: Replace Variables in Header and Footer?
Posted:
Fri Sep 02, 2022 3:28 pm
by swilliams7996
How do you replace the variables in header and footer if the same header is in multiple files? I can replace in main document but not in header.