this is my code:
- Code: Select all
String inputfilepath = "C:\\Users\\compac\\workspace\\poisdo\\sample-docs\\Images.docx";
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
HeaderPart header= wordMLPackage.getHeaderFooterPolicy().getDefaultHeader();
String xml=XmlUtils.marshaltoString(header.getJaxbElement(), true);
HashMap<String, String> mappings = new HashMap<String, String>();
mappings.put("titulo", "Mi titulo :)");
mappings.put("parrafo", "algoP");
Object nuevoObj = XmlUtils.unmarshallFromTemplate(xml, mappings);
Relationship relationship=documentPart.addTargetPart(header);
SectPr sectPr = objectFactory.createSectPr();
HeaderReference headerReference = objectFactory.createHeaderReference();
headerReference.setId(relationship.getId());
headerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(headerReference);
wordMLPackage.save(new File("C:\\", "headerFooter.doc
x"));