Page 1 of 1

Replace text in the header of a document

PostPosted: Fri Apr 22, 2016 12:14 pm
by wschofield
I need help with the same problem using 3.3.0. Essentially, I created a docx template and my code replaces tags in the form ${tag} with the desired text. I use JAXB for document text, table text, etc., and it works well but it doesn't seem to work for header and footer text. I've found examples on how to create a header but I'm really looking for a concise example on how to find a tag in a header and replace it with text.

Any ideas out there?

Re: Replace text in the header of a document

PostPosted: Mon Apr 25, 2016 6:57 pm
by jason
So, what does your code look like?

Here is code to iterate through the header & footer parts:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                for (Entry<PartName, Part> entry : pkg.getParts().getParts().entrySet()) {

                        Part p = entry.getValue();

                        if (p instanceof HeaderPart) {
                                // do something
                        }

                        if (p instanceof FooterPart) {
                                // do something
                        }
                       
                }
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4