Export (0) Print
Expand All

ListObject.TotalsRowRange Property

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

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Range TotalsRowRange { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.Range
A Range that represents the Total row of the ListObject control.

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.

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

Show:
© 2014 Microsoft