Click here to Skip to main content
15,917,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please any one tell me how to add the header and footer for the MS word using html



Thanks in advance
Posted

1 solution

Use Office Open XML SDK to add headers and footers to the word document. As I understand you have an html file where you have header and a footer. So, its easy to do with Office Open XML SDK.
You need to use like this
C#
namespace OOXML
{
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml.Wordprocessing;

    public class WordProcess
    {
        /// read header and footer strings from html and then call AddHeader
        /// by passing the existing word file

        public void AddHeader(string wordFile, string header, string footer)
        {
            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(wordFile, true))
            {
                foreach (HeaderPart hp in wordDoc.MainDocumentPart.HeaderParts)
                {
                    // add/modify header values
                    Header h = hp.Header;
                }

                foreach (FooterPart fp in wordDoc.MainDocumentPart.FooterParts)
                {
                    // add/modify footer values
                    Footer f = fp.Footer;
                }
            }
        }
    }
}


For more help visit this link
http://openxmldeveloper.org/[^]
 
Share this answer
 
Comments
Funny 2013 24-Jul-15 8:21am    
How can this helps to add header and footer, can you please explain ?
pramod.hegde 26-Jul-17 5:36am    
Well, its not a joke !!
If you observe, Header h = hp.Header; will give the document header object.
Later, one can easily 'set string' header to h.

FYI, without knowing the actual user code, providing a complete solution is not possible.

You have any better example ?? then use Solution box, not the Comment !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900