FormatSettings 列舉型別

指定當 ListObject 繫結至資料時,所套用的格式類型。

這個列舉型別的 FlagsAttribute 屬性允許將其成員值以位元組合的方式來使用。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

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

成員

成員名稱 說明
Alignment 指出是否要在預先定義的 XlRangeAutoFormat 中包含對齊。
Border 指出是否要在預先定義的 XlRangeAutoFormat 中包含框線格式。
Font 指出是否要在預先定義的 XlRangeAutoFormat 中包含字型格式
Number 指出是否要在預先定義的 XlRangeAutoFormat 中包含數字格式。
Pattern 指出是否要在預先定義的 XlRangeAutoFormat 中包含樣式格式。
Width 指出是否要在預先定義的 XlRangeAutoFormat 中包含欄寬和列高。

備註

總共有六種設定結合可以指定格式。 您可以使用此列舉型別 (Enumeration) 選擇要將哪一個設定套用至 ListObject。 預設會套用所有的格式化設定。

範例

下列程式碼範例會建立 DataTableListObject,並將 ListObject 繫結至 DataTable。 然後它會將預先定義之 XlRangeAutoFormat 值的字型和模式格式套用至 ListObject

這是示範文件層級自訂的範例。

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

請參閱

參考

Microsoft.Office.Tools.Excel 命名空間