DocumentBase.Tables Property

 

Gets a Tables collection that represents all the tables in the document.

Namespace:   Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

public Tables Tables { get; }

Property Value

Type: Microsoft.Office.Interop.Word.Tables

A Tables collection that represents all the tables in the document.

The following code example adds a new table to the document and populates each cell with a number that is incremented from the previous cell's number. To use this example, run it from the ThisDocument class in a document-level project.

private void DocumentTables()
{
    this.Paragraphs[1].Range.InsertParagraphAfter();

    Word.Table table1 = this.Tables.Add(
        this.Application.Selection.Range,
        4, 2, ref missing, ref missing);

    int cellNumber = 1;
    for (int rowCount = 1; rowCount <= table1.Rows.Count;
        rowCount++)
    {
        for (int columnCount = 1; columnCount <= table1.Columns.Count;
            columnCount++)
        {
            table1.Rows[rowCount].Cells[columnCount].Range.Text =
                cellNumber.ToString();
            cellNumber++;
        }
    }
}
Return to top
Show: