none
How to add header and footer from second page in word using c# RRS feed

  • Question

  • Hi,

    I am creating word document with header & footer. But how to add it from second page.

    here is my header code....

    //Adding Header and Footer
    
                    myDoc.PageSetup.HeaderDistance = oWord.MillimetersToPoints(5F);
                    myDoc.PageSetup.FooterDistance = oWord.MillimetersToPoints(0.5F);               
                    //ENTERING A PARAGRAPH BREAK "ENTER"
                    //Hearder starts here
                    Word.Range oRange = myDoc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                    Word.Table oTable = myDoc.Tables.Add(oRange, 1, 3, ref oMissing, ref oMissing);
                    int r, c;
                    string strText="";
                    for (r = 1; r <= 1; r++)
                        for (c = 1; c <= 3; c++)
                        {
                            if (c == 1) {  strText = LHEADER ; }
                            else if (c == 2) { strText = CHEADER ; }
                            else if (c == 3) { strText = RHEADER; }
    
                            oTable.Cell(r, c).Range.Text = strText;
                            oTable.Cell(r, c).Range.Font.Name = "Times New Roman";
                            oTable.Cell(r, c).Range.Font.Size = 15;
                        }
                    //The col1 cell
                    oTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                    //The col2 cell
                    oTable.Cell(1, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                    //The col3 cell
                    oTable.Cell(1, 3).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;

    Thanks in advance.


    Experience the innovation with perfection.

    Thursday, August 16, 2012 10:20 AM

Answers

  • "Pranav Vaidya" wrote in message news:2a33f504-6756-4aea-85fe-80dd927a5628@communitybridge.codeplex.com...
    If you want a different header on second page onwards, just insert a section after first page and add header for section 2 which would be starting from page 2.
    Also make sure the header is not linked to previous section.

       
       
    To change the header for page two and subsequent pages, you don’t need a section break. Just enable the “Different first page” option in Page Setup. In Word’s object model, you’ll have to set the DifferentFirstPageHeaderFooter property to True (for the relevant PageSetup objects).

    Stefan Blom, Microsoft Word MVP

    Thursday, August 16, 2012 6:27 PM
  • Hi Stefan Blom,

    thanks for reply, yes you are right i want header from second page i don't want header and footer on first page. 

    Really helpful.


    Experience the innovation with perfection.


    • Edited by Bhagawat Monday, August 20, 2012 4:32 AM
    • Marked as answer by Bhagawat Monday, August 20, 2012 4:32 AM
    Monday, August 20, 2012 4:26 AM

All replies

  • Hi,

    You question is not clear enough. What do you mean by "Add from second page"- Do you mean you want the same header as shown on second page or do you want the header to skip first page and start from second?

    If you want a different header on second page onwards, just insert a section after first page and add header for section 2 which would be starting from page 2.

    Also make sure the header is not linked to previous section.

    Thanks.


    Hope this helps!! Regards, Pranav Vaidya PS: If my reply has resolved the issue you are facing please mark it as answer so that it will help others on the forum who may have similar issue.

    Thursday, August 16, 2012 2:56 PM
  • "Pranav Vaidya" wrote in message news:2a33f504-6756-4aea-85fe-80dd927a5628@communitybridge.codeplex.com...
    If you want a different header on second page onwards, just insert a section after first page and add header for section 2 which would be starting from page 2.
    Also make sure the header is not linked to previous section.

       
       
    To change the header for page two and subsequent pages, you don’t need a section break. Just enable the “Different first page” option in Page Setup. In Word’s object model, you’ll have to set the DifferentFirstPageHeaderFooter property to True (for the relevant PageSetup objects).

    Stefan Blom, Microsoft Word MVP

    Thursday, August 16, 2012 6:27 PM
  • Hi Stefan Blom,

    thanks for reply, yes you are right i want header from second page i don't want header and footer on first page. 

    Really helpful.


    Experience the innovation with perfection.


    • Edited by Bhagawat Monday, August 20, 2012 4:32 AM
    • Marked as answer by Bhagawat Monday, August 20, 2012 4:32 AM
    Monday, August 20, 2012 4:26 AM