DocumentBase.Tables 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 Tables 集合,该集合表示文档中的所有表。
public Microsoft.Office.Interop.Word.Tables Tables { get; }
属性值
一个 Tables 集合,表示文档中的所有表。
示例
下面的代码示例向文档中添加一个新表,并使用从上一个单元格的数字递增的数字填充每个单元格。 若要使用此示例,请在 ThisDocument 文档级项目的类中运行它。
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++;
}
}
}
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