WorksheetBase.Rows 属性

获取一个表示工作表上一个或多个行的 Range 对象。

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

语法

声明
Public ReadOnly Property Rows As Range
    Get
public Range Rows { get; }

属性值

类型:Microsoft.Office.Interop.Excel.Range
一个表示工作表上一个或多个行的 Range 对象。

备注

当不带参数使用时,此属性将返回包含工作表上所有行的 Range 对象。

此属性可以与下列可选参数搭配,用于获取工作表上的特定行。 如果使用此属性时带有参数,则返回值是一个必须强制转换为 Range 的对象。

Parameter

说明

RowIndex

要获取的一行或多行的索引。

若要获取单一行,请传递指定了您要获取的行的索引的整数。 行索引从 1 开始。

若要获取多个连续的行,必须以格式“first row:last row”传递字符串。 例如,要获取 1 至 5 行,请传递“1:5”。

ColumnIndex

不要使用此参数。 如果尝试向该参数传递值,该属性将会引发 COMException

示例

下面的代码示例使用 Rows 属性设置工作表上前五行中所有单元格的字体的颜色、名称、大小和加粗程度。

此示例针对的是文档级自定义项。 若要进行此代码,请将它复制到项目中的一个工作表类中。

Private Sub SetRowsFont()
    Dim fillRows As Excel.Range = TryCast(Me.Rows("1:5"), Excel.Range)

    With fillRows.Font
        ' Set the font color to blue (RGB value 00 00 FF), and set other font properties.
        .Color = &HFF0000
        .Name = "Arial"
        .Size = 14
        .Bold = False
    End With

    ' Test the changes by writing a value to all the row cells.
    fillRows.Value2 = "This is a test"
End Sub
private void SetRowsFont()
{
    Excel.Range fillRows = (Excel.Range)this.Rows["1:5", missing];
    Excel.Font rowsFont = fillRows.Font;

    // Set the font color to blue (RGB value 00 00 FF), and set other font properties.
    rowsFont.Color = 0xFF0000;
    rowsFont.Name = "Arial";
    rowsFont.Size = 14;
    rowsFont.Bold = false;

    // Test the changes by writing a value to all the row cells.
    fillRows.Value2 = "This is a test";
}

.NET Framework 安全性

请参见

参考

WorksheetBase 类

Microsoft.Office.Tools.Excel 命名空间