Condividi tramite


ListObject.TotalsRowRange Property

Definition

Gets a Range that represents the Total row of the ListObject control.

public:
 property Microsoft::Office::Interop::Excel::Range ^ TotalsRowRange { Microsoft::Office::Interop::Excel::Range ^ get(); };
public Microsoft.Office.Interop.Excel.Range TotalsRowRange { get; }
member this.TotalsRowRange : Microsoft.Office.Interop.Excel.Range
Public ReadOnly Property TotalsRowRange As Range

Property Value

A Range that represents the Total row of the ListObject control.

Examples

The following code example creates a DataTable and a ListObject, and binds the ListObject to the DataTable. It then gets the range that contains the Total row and changes the Total row font to italic.

This example is for a document-level customization.

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;
}
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

Remarks

This property returns a Range only if the Total row is showing in the ListObject control. If the Total row is not showing, it returns null.

Applies to