how to add header and footer to docx file using ooxml format. RRS feed

  • Question

  • hi i m new to ooxml format
    i m doing word diff of two docx files and after taking diff i want to write docx file.
    here i have a problem that how to write header and footer after i get diff.
    i know that there is different file of header and footer but for that i have to also include link to document.xml and rels file.
    Is there any easy way to add contents of header and footer.
    n another problem is that, does ooxml store any header or footer names(msword displays name of header and footer) ?
    Tuesday, May 6, 2008 10:04 AM

All replies

  • Did you had an answer ?


    I've the same problem.


    Wednesday, July 9, 2008 9:48 AM
  • To add an header / footer you need to do three things:


    1. Create a Part (header.xml / footer.xml) in the docx. All the content (text, images) for the header / footer goes in here

    2. Associate a relationshipId to the part and add it to the document.xml.rels file, this is located in package- >word\_rels folder. It would look like this


    <?xml version="1.0" encoding="utf-8"?>


    <Relationship Type="" Target="/word/footer.xml" Id="R504f6e07bc7941e6" />



    3. Update the relationshipid in the document.xml, this is done by adding a new element to the secPtr section of the document.xml


    <wTongue TiedectPr xmlns:w="">

    <w:footerReference w:type="default" r:id="R504f6e07bc7941e6" xmlns:r="" />


    </wTongue TiedectPr>


    PS: If you have images etc in the header / footer you will have to create an addition .rels file for those association.



    If you need to do all this programmatically, the OpenXml SDK provide the HeaderPart / FooterPart classes that do all the low level pumbing of creating relationships for you



    Sunday, July 20, 2008 2:12 PM
  • Hi,
    How are you taking the difference between two docx files? I have to take the difference and write to another docx customizing the content.
    Tuesday, February 16, 2010 6:04 AM
  • Have you guys looked into using the Open XML SDK Productivity tool that is part of the Open XML SDK. This tool allows you to see the XML difference between two Open XML files. In addition, the tool automatically generates SDK code necessary to change the first docment into the second document. This tool is a great way to learn about Open XML and the Open XML SDK.
    Zeyad Rajabi (MS)
    Thursday, February 18, 2010 6:30 AM