次の方法で共有


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 の列の幅と行の高さを含めるかどうかを示します。.

解説

書式は 6 つの設定を組み合わせて指定します。 この列挙体を使用すると、ListObject にどの設定を適用するかを選択できます。 既定では、すべての書式設定が適用されます。

次のコード例は、DataTableListObject を作成し、ListObjectDataTable にバインドします。 次に、定義済みの 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 名前空間