Export (0) Print
Expand All
Expand Minimize

FormatSettings Enumeration

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

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

[FlagsAttribute] 
public enum FormatSettings

 Member nameDescription
AlignmentIndicates whether to include an alignment in the predefined XlRangeAutoFormat
BorderIndicates whether to include border formats in the predefined XlRangeAutoFormat
FontIndicates whether to include font formats in the predefined XlRangeAutoFormat 
NumberIndicates whether to include the number formats in the predefined XlRangeAutoFormat
PatternIndicates whether to include the pattern formats in the predefined XlRangeAutoFormat
WidthIndicates whether to include the column width and row height in the predefined XlRangeAutoFormat

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.

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.

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

Show:
© 2015 Microsoft