Page 1 of 1

how to modify the text in the head

PostPosted: Tue Jul 27, 2010 5:00 am
by isaac
I'm trying to modify the text of the header with templets but the document generated is same as above.

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"));

Re: how to modify the text in the head

PostPosted: Tue Jul 27, 2010 7:37 pm
by jason
Does your document already contain header? If so, why are you calling addTargetPart?

If it doesn't, you need to create it first. See the HeaderFooter sample.

Also, your code doesn't headerPart.setJaxbElement to your nuevoObj