none
Editing table in footer Word document 2007 C# RRS feed

  • Question

  • Hi All )

    I need to edit a table , which is located in the footer Word Document 2007 ( C#).
    I know how to refer to an existing table in the document , but how to do this if the table in the footer ?

    Give a tip .
    Thanks


    • Edited by MihalyshMS Monday, April 9, 2012 1:51 PM
    Monday, April 9, 2012 1:50 PM

Answers

  • I asked , I answer ))

    Word.Range range = document.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    

    And now edit the table in footer

     Word.Table table = range.Tables[1];
                table.Cell(1,1).Range.Text = "TestText";

    Monday, April 9, 2012 6:20 PM

All replies

  • Footers are a layer within Sections so you have to iterate thru the Document's Sections and look at each Footer to see if there is a Table within it.  I can't help you with the C# code but here is a VBA version that should give you a start.

    Sub TableInFooters()
        Dim doc As Word.Document
        Dim rng As Word.Range
        Dim sec As Word.Section
        Dim hfRng As Word.HeaderFooter
        Set doc = Word.ActiveDocument
        
        For Each sec In doc.Sections
            For Each hfRng In sec.Footers
                If hfRng.LinkToPrevious = False Then
                    If hfRng.Range.Tables.count > 0 Then
                        Set rng = hfRng.Range.Tables(1).Range
                        'now do something with the table
                    End If
                End If
            Next hfRng
        Next sec
    End Sub

     


    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, April 9, 2012 4:06 PM
  • I asked , I answer ))

    Word.Range range = document.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    

    And now edit the table in footer

     Word.Table table = range.Tables[1];
                table.Cell(1,1).Range.Text = "TestText";

    Monday, April 9, 2012 6:20 PM