Freigeben über


FormatSettings Enum

Definition

Specifies the type of formatting that is applied to the ListObject when it is bound to data.

This enumeration supports a bitwise combination of its member values.

public enum class FormatSettings
[System.Flags]
public enum FormatSettings
[<System.Flags>]
type FormatSettings = 
Public Enum FormatSettings
Inheritance
FormatSettings
Attributes

Fields

Name Value Description
Number 1

Indicates whether to include the number formats in the predefined XlRangeAutoFormat.

Font 16

Indicates whether to include font formats in the predefined XlRangeAutoFormat

Alignment 256

Indicates whether to include an alignment in the predefined XlRangeAutoFormat.

Border 4096

Indicates whether to include border formats in the predefined XlRangeAutoFormat.

Pattern 65536

Indicates whether to include the pattern formats in the predefined XlRangeAutoFormat.

Width 1048576

Indicates whether to include the column width and row height in the predefined XlRangeAutoFormat.

Examples

The following code example creates a DataTable and a ListObject, and binds the ListObject to the DataTable. It then applies the font and pattern formats of a predefined XlRangeAutoFormat value to the ListObject.

This example is for a document-level customization.

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

Remarks

There are six settings that combine to specify formatting. Using this enumeration, you can select which settings to apply to the ListObject. By default all format settings are applied.

Applies to