ListObject.TotalsRowRange 属性

获取一个表示 ListObject 控件的总计行的 Range

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

语法

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

属性值

类型:Microsoft.Office.Interop.Excel.Range
一个表示 ListObject 控件的总计行的 Range

备注

只有当 ListObject 控件中显示总计行时,此属性才返回 Range。如果未显示总计行,它将返回 nullnull 引用(在 Visual Basic 中为 Nothing)。

示例

下面的代码示例创建一个 DataTable 和一个 ListObject,并将该 ListObject 绑定到该 DataTable。然后获取包含总计行的范围并将总计行的字体更改为斜体。

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

Private Sub ListObject_TotalsRowRange()
    ' Create a new DataSet and DataTable.
    Dim ds As New DataSet()
    Dim dt As DataTable = ds.Tables.Add("Sales")
    dt.Columns.Add(New DataColumn("Name"))
    dt.Columns.Add(New DataColumn("Quarter1"))

    ' Add a new row to the DataTable.
    Dim dr1 As DataRow = dt.NewRow()
    dr1("Name") = "Sidney"
    dr1("Quarter1") = "150"
    dt.Rows.Add(dr1)
    Dim dr2 As DataRow = dt.NewRow()
    dr2("Name") = "Julia"
    dr2("Quarter1") = "175"
    dt.Rows.Add(dr2)

    ' Create a list object.
    Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
        Me.Controls.AddListObject(Me.Range("A1"), "List1")

    ' Bind the list object to the DataTable.
    List1.AutoSetDataBoundColumnHeaders = True
    List1.SetDataBinding(ds, "Sales", "Name", "Quarter1")
    List1.ShowTotals = True

    ' Get the header row range and set the font to bold.
    Dim totalRow As Excel.Range = List1.TotalsRowRange
    totalRow.Cells.Font.Italic = True
End Sub

private void ListObject_TotalsRowRange()
{
    // Create a new DataSet and DataTable.
    DataSet ds = new DataSet();
    DataTable dt = ds.Tables.Add("Sales");
    dt.Columns.Add(new DataColumn("Name"));
    dt.Columns.Add(new DataColumn("Quarter1"));

    // Add a new row to the DataTable.
    DataRow dr1 = dt.NewRow();
    dr1["Name"] = "Sidney";
    dr1["Quarter1"] = "150";
    dt.Rows.Add(dr1);
    DataRow dr2 = dt.NewRow();
    dr2["Name"] = "Julia";
    dr2["Quarter1"] = "175";
    dt.Rows.Add(dr2);

    // Create a list object.
    Microsoft.Office.Tools.Excel.ListObject list1 =
        this.Controls.AddListObject(
        this.Range["A1"], "list1");

    // Bind the list object to the DataTable.
    list1.AutoSetDataBoundColumnHeaders = true;
    list1.SetDataBinding(ds, "Sales", "Name",
        "Quarter1");
    list1.ShowTotals = true;

    // Get the header row range and set the font to bold.
    Excel.Range totalRow = list1.TotalsRowRange;
    totalRow.Cells.Font.Italic = true;
}

.NET Framework 安全性

请参见

参考

ListObject 接口

Microsoft.Office.Tools.Excel 命名空间