Share via


ListObject.DataBoundFormatSettings (Propiedad)

Obtiene o establece que FormatSettings de XlRangeAutoFormat especificado se aplique al control ListObject.

Espacio de nombres:  Microsoft.Office.Tools.Excel
Ensamblado:  Microsoft.Office.Tools.Excel (en Microsoft.Office.Tools.Excel.dll)

Sintaxis

'Declaración
Property DataBoundFormatSettings As FormatSettings
FormatSettings DataBoundFormatSettings { get; set; }

Valor de propiedad

Tipo: Microsoft.Office.Tools.Excel.FormatSettings
Combinación bit a bit de los valores de FormatSettings.

Comentarios

De forma predeterminada, se aplica toda la información del estilo XlRangeAutoFormat.Sin embargo, se pueden quitar los elementos específicos para que el estilo no se aplique a dichos elementos.Estos valores son los siguientes:

  • Número

  • Fuente

  • Alineación

  • Borde

  • Modelo

  • Ancho

Para aplicar únicamente los estilos seleccionados, establezca DataBoundFormatSettings antes de establecer la propiedad DataBoundFormat.DataBoundFormatSettings no funcionará si DataBoundFormat ya está establecido.

Ejemplos

El ejemplo de código siguiente crea DataTable y ListObject, y enlaza el control ListObject al control DataTable.Establece la FormatSettings para que se aplique a ListObject y utiliza un valor de XlRangeAutoFormat para proporcionar el formato.

Se trata de un ejemplo para una personalización en el nivel del documento.

    Private Sub ListObject_DataBoundFormatSettings()
        ' 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")

        ' Specify the format settings that you want to include.
        ' In this example, only the Font and Pattern 
        ' settings are applied.
        List1.DataBoundFormatSettings = _
            Microsoft.Office.Tools.Excel.FormatSettings.Font Or _
            Microsoft.Office.Tools.Excel.FormatSettings.Pattern

        ' Add a format to the list object.
        List1.DataBoundFormat = _
            Excel.XlRangeAutoFormat.xlRangeAutoFormatList2

    End Sub

private void ListObject_DataBoundFormatSettings()
{
    // 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");

    // Specify the format settings that you want to include.
    // In this example, only the Font and Pattern 
    // settings are applied.
    list1.DataBoundFormatSettings =
        Microsoft.Office.Tools.Excel.FormatSettings.Font |
        Microsoft.Office.Tools.Excel.FormatSettings.Pattern;

    // Add a format to the list object.
    list1.DataBoundFormat = 
        Excel.XlRangeAutoFormat.xlRangeAutoFormatList2;
}

Seguridad de .NET Framework

Vea también

Referencia

ListObject Interfaz

Microsoft.Office.Tools.Excel (Espacio de nombres)