At the moment I have no idea how to do this because I do not have much experience with docx4j.
Current code status for removing header:
final WordprocessingMLPackage wordProcessingPackageHeader = DocxUtils
.getWordProcessingPackage(DocxUtils.class.getResourceAsStream("main-document.docx"));
- Code: Select all
final RelationshipsPart relationshipsPart = wordProcessingPackageHeader.getMainDocumentPart().getRelationshipsPart();
final List<Relationship> relationships = relationshipsPart.getRelationships().getRelationship();
for (final Relationship r : relationships) {
if (r.getType().equals(Namespaces.HEADER)) {
final Part part = relationshipsPart.getPart(r);
part.remove();
}
}
Is it necessary to remove the header before setting it or can I also replace it?
How could I remove the header of the main document and then set the header from the template doc?