共用方式為


ListObject.TotalsRowRange 屬性

取得 Range,表示 ListObject 控制項的總計列。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
ReadOnly Property TotalsRowRange As Range
    Get
Range TotalsRowRange { get; }

屬性值

型別:Microsoft.Office.Interop.Excel.Range
Range ,表示 ListObject 控制項的總計列。

備註

這個屬性只在總計列正顯示在 ListObject 控制項時才傳回 Range。 如果沒有在這個總計列,則會傳回 nullNull 參照 (即 Visual Basic 中的 Nothing)。

範例

下列程式碼範例會建立 DataTableListObject,並將 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", missing], "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 命名空間