FormatSettings 枚举

指定 ListObject 在绑定到数据时所应用的格式设置的类型。

此枚举有一个 FlagsAttribute 特性,通过该特性可使其成员值按位组合。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
<FlagsAttribute> _
Public Enumeration FormatSettings
[FlagsAttribute]
public enum FormatSettings

成员

成员名称 说明
Number 指定是否在预定义的 XlRangeAutoFormat 中包括数字格式。
Font 指定是否在预定义的 XlRangeAutoFormat 中包括字体格式。
Alignment 指定是否在预定义的 XlRangeAutoFormat 中包括对齐方式。
Border 指定是否在预定义的 XlRangeAutoFormat 中包括边框格式。
Pattern 指定是否在预定义的 XlRangeAutoFormat 中包括模式格式。
Width 指定是否在预定义的 XlRangeAutoFormat 中包括列宽和行高。

备注

共有六个设置用以指定格式设置。 使用此枚举,可选择要应用到 ListObject 的设置。 默认情况下应用所有格式设置。

示例

下面的代码示例创建一个 DataTable 和一个 ListObject,并将该 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", 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;
}

请参见

参考

Microsoft.Office.Tools.Excel 命名空间