- Code: Select all
HeaderPart headerPartOdd = new HeaderPart();
HeaderPart headerPartEven = new HeaderPart();
Relationship relOdd = wordMLPackage.getMainDocumentPart().addTargetPart(headerPartOdd);
Relationship relEven = wordMLPackage.getMainDocumentPart().addTargetPart(headerPartEven);
ObjectFactory objectFactory = new ObjectFactory();
// create header content using a header open xml skeleton
String headerTextOdd = getXMLString("header_text_odd");
String headerTextEven = getXMLString("header_text_even");
// headerText = headerText.replace("productName", productName);
Hdr hdrOdd = (Hdr) XmlUtils.unmarshalString(headerTextOdd);
Hdr hdrEven = (Hdr) XmlUtils.unmarshalString(headerTextEven);
headerPartOdd.setJaxbElement(hdrOdd);
headerPartEven.setJaxbElement(hdrEven);
List<SectionWrapper> sections = wordMLPackage.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
if (sectPr == null) {
sectPr = objectFactory.createSectPr();
wordMLPackage.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
// set header reference
HeaderReference headerReferenceOdd = objectFactory.createHeaderReference();
headerReferenceOdd.setId(relOdd.getId());
headerReferenceOdd.setType(HdrFtrRef.DEFAULT);
HeaderReference headerReferenceEven = objectFactory.createHeaderReference();
headerReferenceEven.setId(relEven.getId());
headerReferenceEven.setType(HdrFtrRef.EVEN);
sectPr.getEGHdrFtrReferences().add(headerReferenceEven);
sectPr.getEGHdrFtrReferences().add(headerReferenceOdd);
but only the "even" header is showing up.
I can't seem to figure out why