ListObject.DataBoundFormat 屬性

取得或設定有資料繫結之 ListObject 控制項的格式化樣式。

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

語法

'宣告
Property DataBoundFormat As XlRangeAutoFormat
XlRangeAutoFormat DataBoundFormat { get; set; }

屬性值

型別:Microsoft.Office.Interop.Excel.XlRangeAutoFormat
其中一個 XlRangeAutoFormat 值。

備註

在您能夠使用這個屬性之前,ListObject 控制項必須繫結至資料。

指定的格式會套用至整個清單物件,包括稍後加入的列。

若要移除格式化,請將 DataBoundFormat 設定為 xlRangeAutoFormatNone

可使用 DataBoundFormatSettings,排除特定類型的格式化,例如樣式的圖樣、字型或寬度。

範例

下列程式碼範例會建立 DataTableListObject,並將 ListObject 繫結至 DataTable。 範例接著使用 XlRangeAutoFormat 值,格式化 ListObject

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

    Private Sub ListObject_DataBoundFormat()
        ' 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")

        ' Add a format to the list object.
        List1.DataBoundFormat = _
            Excel.XlRangeAutoFormat.xlRangeAutoFormatList2

    End Sub

private void ListObject_DataBoundFormat()
{
    // 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");

    // Add a format to the list object.
    list1.DataBoundFormat = 
        Excel.XlRangeAutoFormat.xlRangeAutoFormatList2;
}

.NET Framework 安全性

請參閱

參考

ListObject 介面

Microsoft.Office.Tools.Excel 命名空間