Udostępnij za pośrednictwem


Document.Tables Property (2007 System)

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

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

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property Tables As Tables
'Usage
Dim instance As Document 
Dim value As Tables 

value = instance.Tables
[BrowsableAttribute(false)]
public Tables Tables { get; }
[BrowsableAttribute(false)]
public:
property Tables^ Tables {
    Tables^ get ();
}
public function get Tables () : Tables

Property Value

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

Examples

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.

This example is for a document-level customization.

Private Sub DocumentTables()
    Me.Paragraphs(1).Range.InsertParagraphAfter()

    Dim table1 As Word.Table = Me.Tables.Add(Me.Application.Selection.Range, 4, 2)

    Dim cellNumber As Integer = 1
    Dim rowCount As Integer 
    For rowCount = 1 To table1.Rows.Count
        Dim columnCount As Integer 
        For columnCount = 1 To table1.Columns.Count
            table1.Rows(rowCount).Cells(columnCount).Range.Text = cellNumber.ToString()
            cellNumber += 1
        Next columnCount
    Next rowCount

End Sub
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++;
        }
    }
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace