ListObject.HeaderRowRange Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém um Range que representa o intervalo ao qual o cabeçalho se aplica.
public Microsoft.Office.Interop.Excel.Range HeaderRowRange { get; }
Valor da propriedade
Um Range que representa o intervalo ao qual o cabeçalho se aplica.
Exemplos
O exemplo de código a seguir cria um DataTable e um ListObject, além de associar o ListObject ao DataTable. Em seguida, ele obtém o intervalo que contém a linha de cabeçalho e altera a fonte da linha de cabeçalho para negrito.
Este exemplo destina-se a uma personalização no nível de documento.
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";
dt.Rows.Add(dr);
// 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, "Customers", "LastName",
"FirstName");
// Get the header row range and set the font to bold.
Excel.Range headerRow = list1.HeaderRowRange;
headerRow.Cells.Font.Bold = true;
}
Private Sub ListObject_HeaderRowRange()
' Create a new DataSet and DataTable.
Dim ds As New DataSet()
Dim dt As DataTable = ds.Tables.Add("Customers")
dt.Columns.Add(New DataColumn("LastName"))
dt.Columns.Add(New DataColumn("FirstName"))
' Add a new row to the DataTable.
Dim dr As DataRow = dt.NewRow()
dr("LastName") = "Chan"
dr("FirstName") = "Gareth"
dt.Rows.Add(dr)
' 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, "Customers", _
"LastName", "FirstName")
' Get the header row range and set the font to bold.
Dim headerRow As Excel.Range = List1.HeaderRowRange
headerRow.Cells.Font.Bold = True
End Sub
Comentários
Se não houver nenhuma linha de cabeçalho, HeaderRowRange retornará null .