none
How to: Add Different Headers and Footers to Word Documents in C#/ASp.net?

    Question

  • You cannot vote on your own post
    0

    Hi,

    I wanted to display different Header/Footer to each pages in the word Document.

    I searched but I did not get proper solution.

    I am able to find out different Header/Footer for first page and Odd Even pages but I needed different Header/Footer to each pages of word doc.

    Could any body help me out?

    Thanks!!

    Thursday, September 30, 2010 11:45 AM

Answers

  • Hi Shubha

    <<Ya. User can do something with these documents But not anything at the bottom (or top) of a page. >>

    Then I don't really see any good way to accomplish what you have in mind. As soon as the user starts editing (adding or deleting text), the text is going to move up or down in the document - to another page, eventually.

    If you use a Shape to anchor a text box (for example) to a paragraph, you can get it to stay on the same place on whichever page the anchor is on. But if that paragraph moves to a different page, so will the Shape.

    Using the Header/Footer is not practical for a similar reason. In order to define a different header or footer for every page, each page would need to be separated from the next by a Section Break. As the text is edited, this could push a section break to the next page.

    It does not matter whether you use a macro or asp.net - the problem remains the same. Word was not designed to do what you want it to do.

    If you were creating these objects at the end of the editing process, it would be possible. But not at document creation if the user is going to be editing.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Thursday, October 07, 2010 8:56 AM
    Friday, October 01, 2010 3:56 PM
    Moderator

All replies

  • Hi Shubha

    The concept of a "header" or "footer" is that the content is basically the same for all pages. Word has fields that can provide some dynamic content (page number, for example), but basically the idea is that the content is static and always the same. Or changes only for the first page, or by section, or on odd/even pages.

    If you want something different at the top of each and every page, do not use the document header. Instead, write the information there directly.

    Perhaps if you give us a more exact explanation of your requirment, we can offer other recommendations...


    Cindy Meister, VSTO/Word MVP
    Thursday, September 30, 2010 2:43 PM
    Moderator
  • Hi Cindy,

    YA, I know sir.

    We have word macro with different Header and Footer and we wanted to do it through ASP.net.

    On click of button it will generate Word Doc. For this I wanted to put something different at the top and bottom of the page.

    Footer contains different table on each page also I wanted to display watermark on the last page of doc.

    Is this possible??

    Suggest me  solution plz

    Thanks!

     

    Friday, October 01, 2010 5:11 AM
  • Hi Shubha

    Is the user going to be doing anything with these documents, after they're generated? If yes, how freely may they edit?  (I'm concerned about whether anything at the bottom (or top) of a page is going to moved)

    How long are these documents going to be?

    Which version of Word are you targeting?


    Cindy Meister, VSTO/Word MVP
    Friday, October 01, 2010 6:13 AM
    Moderator
  • Hi Cindy,

    Ya. User can do something with these documents But not anything at the bottom (or top) of a page. 

    To generate this doc using macro takes lots of time(Connecting to DB and fetching data from it ) so that we wanted to moved to ASP.net.

    Right now I am using Word 2003 but I have to take care of compatibility also.

    Thanks!!

    Friday, October 01, 2010 9:16 AM
  • Hi Shubha

    <<Ya. User can do something with these documents But not anything at the bottom (or top) of a page. >>

    Then I don't really see any good way to accomplish what you have in mind. As soon as the user starts editing (adding or deleting text), the text is going to move up or down in the document - to another page, eventually.

    If you use a Shape to anchor a text box (for example) to a paragraph, you can get it to stay on the same place on whichever page the anchor is on. But if that paragraph moves to a different page, so will the Shape.

    Using the Header/Footer is not practical for a similar reason. In order to define a different header or footer for every page, each page would need to be separated from the next by a Section Break. As the text is edited, this could push a section break to the next page.

    It does not matter whether you use a macro or asp.net - the problem remains the same. Word was not designed to do what you want it to do.

    If you were creating these objects at the end of the editing process, it would be possible. But not at document creation if the user is going to be editing.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Thursday, October 07, 2010 8:56 AM
    Friday, October 01, 2010 3:56 PM
    Moderator
  • Hello subha,

    could you please send me the code for to create Header and footer for  word documents using C# .

    your help would be appreciated .

    e-mail is Vkommineni@live.com


    Regards, Vik

    Tuesday, March 13, 2012 5:52 AM