Cell 对象 (Word)Cell object (Word)

代表单个表格单元格。Represents a single table cell. Cell对象是**Cells** 集合的成员。The Cell object is a member of the Cells collection. 单元格 集合表示在指定的对象中的所有单元格。The Cells collection represents all the cells in the specified object.

注解Remarks

使用**单元格(行、 列),其中行为行数和列是列号或单元格**(index),其中 index 是索引号,可返回Cell对象。Use Cell (row, column), where row is the row number and column is the column number, or Cells (index), where index is the index number, to return a Cell object. 下面的示例给第一行中的第二个单元格加底纹。The following example applies shading to the second cell in the first row.

Set myCell = ActiveDocument.Tables(1).Cell(Row:=1, Column:=2) 
myCell.Shading.Texture = wdTexture20Percent

以下示例对第一行的第一个单元格应用底纹。The following example applies shading to the first cell in the first row.

ActiveDocument.Tables(1).Rows(1).Cells(1).Shading _ 
 .Texture = wdTexture20Percent

使用**Add** 方法将Cell对象添加到**Cells** 集合。Use the Add method to add a Cell object to the Cells collection. 您还可以使用 InsertCells 要插入新单元格的 所选内容 对象的方法。You can also use the InsertCells method of the Selection object to insert new cells. 下面的示例在 myTable中添加之前的第一个单元格的单元格。The following example adds a cell before the first cell in myTable.

Set myTable = ActiveDocument.Tables(1) 
myTable.Range.Cells.Add BeforeCell:=myTable.Cell(1, 1)

以下示例设置引用中的第一个表格的前两个单元格范围 ( myRange )。The following example sets a range ( myRange ) that references the first two cells in the first table. 设置此区域后,通过 Merge 方法合并单元格。After the range is set, the cells are combined by the Merge method.

Set myTable = ActiveDocument.Tables(1) 
Set myRange = ActiveDocument.Range(myTable.Cell(1, 1) _ 
 .Range.Start, myTable.Cell(1, 2).Range.End) 
myRange.Cells.Merge

说明Remarks

使用与**** 或**** 集合的**Add** 方法添加的行或列单元格。Use the Add method with the Rows or Columns collection to add a row or column of cells.

使用和Selection对象的**信息** 属性可返回当前行和列号。Use the Information property with a Selection object to return the current row and column number. 下面的示例更改选定内容中的第一个单元格的宽度,然后显示该单元格的行号和列号。The following example changes the width of the first cell in the selection and then displays the cell's row number and column number.

If Selection.Information(wdWithInTable) = True Then 
 With Selection 
 .Cells(1).Width = 22 
 MsgBox "Cell " & .Information(wdStartOfRangeRowNumber) _ 
 & "," & .Information(wdStartOfRangeColumnNumber) 
 End With 
End If

另请参阅See also

Word 对象模型引用Word Object Model Reference