Share via


Enumerazione FormatSettings

Specifica il tipo di formattazione applicata al controllo ListObject quando viene associato ai dati.

Questa enumerazione dispone di un attributo FlagsAttribute che consente una combinazione bit per bit dei valori dei membri.

Spazio dei nomi:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Sintassi

'Dichiarazione
<FlagsAttribute> _
Public Enumeration FormatSettings
[FlagsAttribute]
public enum FormatSettings

Membri

Nome membro Descrizione
Number Indica se includere i formati per i numeri nell'oggetto XlRangeAutoFormat predefinito.
Font Indica se includere i formati per il tipo di carattere nell'oggetto XlRangeAutoFormat predefinito.
Alignment Indica se includere un allineamento nell'oggetto XlRangeAutoFormat predefinito.
Border Indica se includere i formati per il bordo nell'oggetto XlRangeAutoFormat predefinito.
Pattern Indica se includere i formati per il motivo nell'oggetto XlRangeAutoFormat predefinito.
Width Indica se includere la larghezza di colonna e l'altezza di riga nell'oggetto XlRangeAutoFormat predefinito.

Note

Per specificare la formattazione, è possibile utilizzare una combinazione di sei impostazioni. Utilizzando questa enumerazione è possibile selezionare le impostazioni da applicare al controllo ListObject. Per impostazione predefinita vengono applicate tutte le impostazioni di formattazione.

Esempi

Nell'esempio di codice riportato di seguito viene creato un oggetto DataTable e un controllo ListObject, quindi viene eseguita l'associazione tra il controllo ListObject e l'oggetto DataTable. I formati relativi al tipo di carattere e al motivo di un valore dell'oggetto XlRangeAutoFormat predefinito vengono infine applicati al controllo ListObject.

Questo esempio è valido per una personalizzazione a livello di 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", missing], "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;
}

Vedere anche

Riferimenti

Spazio dei nomi Microsoft.Office.Tools.Excel