Page 1 of 1

Replace text variable in header/footer and fix bullet points

PostPosted: Mon Dec 18, 2017 6:07 am
by sm_a
I have tested the following sample code. Unfortunately, this code does not replace the header/footer in the docx document.

https://github.com/plutext/docx4j/blob/ ... place.java

How do I change the code so that it also replaces the header/footer with? I also have bullet points in the docx document which are no longer visible after saving.

Hope someone has a solution for me.

Re: Replace text variable in header/footer and fix bullet po

PostPosted: Mon Dec 18, 2017 11:48 am
by jason
You can adapt https://github.com/plutext/docx4j/blob/ ... .java#L373

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                // Add headers/footers
                RelationshipsPart rp = srcPackage.getMainDocumentPart()
                                .getRelationshipsPart();
                for (Relationship r : rp.getRelationships().getRelationship()) {

                        if (r.getType().equals(Namespaces.HEADER)) {
                                // replace here in ((HeaderPart) rp.getPart(r));
                        } else if (r.getType().equals(Namespaces.FOOTER)) {
                                // replace here in ((FooterPart) rp.getPart(r));
                        }
                }
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


Whatever you are doing with the bullets is probably a separate issue which should be in a new topic please. You'll need to add details to get any help. But you can probably satisfy yourself docx4j's loading/saving isn't the cause, using https://github.com/plutext/docx4j/blob/ ... pTest.java