ListObject.HeaderRowRange Property


Gets a Range that represents the range of the header row.

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

Range HeaderRowRange { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.Range

A Range that represents the range of the header row.

If there is no header row, HeaderRowRange 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 header row and changes the header row font to bold.

This example is for a document-level customization.

private void ListObject_HeaderRowRange()
    // Create a new DataSet and DataTable.
    DataSet ds = new DataSet();
    DataTable dt = ds.Tables.Add("Customers");
    dt.Columns.Add(new DataColumn("LastName"));
    dt.Columns.Add(new DataColumn("FirstName"));

    // Add a new row to the DataTable.
    DataRow dr = dt.NewRow();
    dr["LastName"] = "Chan";
    dr["FirstName"] = "Gareth";

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

    // Bind the list object to the DataTable.
    list1.AutoSetDataBoundColumnHeaders = true;
    list1.SetDataBinding(ds, "Customers", "LastName",

    // Get the header row range and set the font to bold.
    Excel.Range headerRow = list1.HeaderRowRange;
    headerRow.Cells.Font.Bold = true;
Return to top