how can i modify the text in the head?
Posted: Tue Aug 16, 2011 3:05 pm
hi,all:
i want to modify the text in the head,below is my code
but The results did not change...
the attachement is my sample doc.
how can i modify codes to achieve my goal?
thanks !
tosswang
i want to modify the text in the head,below is my code
- Code: Select all
import java.io.File;
import java.util.HashMap;
import java.util.List;
import org.docx4j.XmlUtils;
import org.docx4j.model.structure.HeaderFooterPolicy;
import org.docx4j.model.structure.SectionWrapper;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart;
public class TestMidfyHeader
{
public static void main(String[] str)throws Exception
{
String inputfilepath = "C:\\workspace\\Doc1.docx";
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
List<SectionWrapper> sectionWrappers = wordMLPackage.getDocumentModel().getSections();
for (SectionWrapper sw : sectionWrappers)
{
HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
HeaderPart header= hfp.getDefaultHeader();
String xml=XmlUtils.marshaltoString(header.getJaxbElement(), true);
HashMap<String, String> mappings = new HashMap<String, String>();
mappings.put("[[label0]]", "Mi titulo :)");
XmlUtils.unmarshallFromTemplate(xml, mappings);
}
wordMLPackage.save(new File("C:\\", "headerFooter.docx"));
}
}
but The results did not change...
the attachement is my sample doc.
how can i modify codes to achieve my goal?
thanks !
tosswang