NamedRange.Cells 属性

获取一个表示 NamedRange 控件中单元格的 Microsoft.Office.Interop.Excel.Range

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
ReadOnly Property Cells As Range
Range Cells { get; }

属性值

类型:Microsoft.Office.Interop.Excel.Range
一个表示 NamedRange 控件中单元格的 Microsoft.Office.Interop.Excel.Range

示例

下面的代码示例创建一个 NamedRange 并将其内部着成绿色。然后,它显示一系列消息,指出 NamedRange 中单元格、列和行的数目。

此示例针对的是文档级自定义项。

Private compositeRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub DisplayRangeComposition()
    compositeRange = Me.Controls.AddNamedRange( _
        Me.Range("B2", "E5"), "compositeRange")
    compositeRange.Cells.Interior.Color = &HFF00
    MessageBox.Show("The range has " & _
        compositeRange.Count & " cells.")
    MessageBox.Show("The range has " & _
        compositeRange.Columns.Count & " columns.")
    MessageBox.Show("The range has " & _
        compositeRange.Rows.Count & " rows.")
End Sub
Microsoft.Office.Tools.Excel.NamedRange compositeRange;
private void DisplayRangeComposition()
{
    compositeRange = this.Controls.AddNamedRange(
        this.Range["B2", "E5"], "compositeRange");
    compositeRange.Cells.Interior.Color = 0xFF00;
    MessageBox.Show("The range has " + compositeRange.Count + 
        " cells.");
    MessageBox.Show("The range has " + 
        compositeRange.Columns.Count + " columns.");
    MessageBox.Show("The range has " + 
        compositeRange.Rows.Count + " rows.");
}

.NET Framework 安全性

请参见

参考

NamedRange 接口

Microsoft.Office.Tools.Excel 命名空间