ListObject.DataBoundFormatSettings, propriété

Obtient ou définit les FormatSettings des XlRangeAutoFormat spécifiés qui sont appliqués au contrôle ListObject.

Espace de noms :  Microsoft.Office.Tools.Excel
Assembly :  Microsoft.Office.Tools.Excel (dans Microsoft.Office.Tools.Excel.dll)

Syntaxe

'Déclaration
Property DataBoundFormatSettings As FormatSettings
FormatSettings DataBoundFormatSettings { get; set; }

Valeur de propriété

Type : Microsoft.Office.Tools.Excel.FormatSettings
Combinaison d'opérations de bits des valeurs FormatSettings.

Notes

Par défaut, toutes les informations du style XlRangeAutoFormat sont appliquées.Toutefois, des éléments spécifiques peuvent être supprimés afin que le style ne soit pas appliqué à ces éléments.Ces éléments sont les suivants :

  • Numéro

  • Police

  • Alignement

  • Bordure

  • Modèle

  • Largeur

Pour appliquer uniquement les styles sélectionnés, définissez DataBoundFormatSettings avant que la propriété DataBoundFormat ne soit définie.DataBoundFormatSettings ne fonctionnera pas si DataBoundFormat est déjà défini.

Exemples

L'exemple de code suivant crée un DataTable et un ListObject, et lie ListObject à DataTable.Il définit ensuite le FormatSettings à appliquer à ListObject, et utilise une valeur XlRangeAutoFormat pour fournir le format.

Cet exemple illustre une personnalisation au niveau du document.

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

Sécurité .NET Framework

Voir aussi

Référence

ListObject Interface

Microsoft.Office.Tools.Excel, espace de noms