Compartir a través de


DocumentBase.Tables (Propiedad)

Obtiene una colección Tables que representa todas las tablas del documento.

Espacio de nombres:  Microsoft.Office.Tools.Word
Ensamblado:  Microsoft.Office.Tools.Word.v4.0.Utilities (en Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Sintaxis

'Declaración
Public ReadOnly Property Tables As Tables
public Tables Tables { get; }

Valor de propiedad

Tipo: Microsoft.Office.Interop.Word.Tables
Una colección Tables que representa todas las tablas del documento.

Ejemplos

En el siguiente ejemplo de código se agrega una nueva tabla al documento y se rellena cada celda con un número que es resultado de incrementar el número de la celda anterior.Para usar este ejemplo, ejecútelo desde la clase ThisDocument en un proyecto de nivel de documento.

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

Seguridad de .NET Framework

Vea también

Referencia

DocumentBase Clase

Microsoft.Office.Tools.Word (Espacio de nombres)