Share via


DocumentBase.Tables 屬性

取得 Tables 集合,表示在文件中的所有表格。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
Public ReadOnly Property Tables As Tables
public Tables Tables { get; }

屬性值

型別:Microsoft.Office.Interop.Word.Tables
Tables 集合,表示在文件中的所有表格。

範例

下列程式碼範例會將新表格加入至文件,並且在每個儲存格填入從上一個儲存格所累加的數字。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

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 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間