Spread WPF 18
Features / Table / Table Styles
In This Topic
    Table Styles
    In This Topic

    Spread for WPF allows you to customize tables by configuring and applying different styles while working with spreadsheets. Table styles help you apply a consistent and visually appealing format to tables, which improves readability and data organization. A table can be styled in one of two ways: built-in or custom.

    Built-in Styles

    Built-in styles are pre-defined styles and include a variety of themes with different color schemes, font settings, borders, and other style options. To apply built-in styles, use the BuiltInTableStyles enumeration of the GrapeCity.Spreadsheet namespace.

    The following example code applies the built-in style “TableStyleDark11” to the table.

    Copy Code
    // Create a table.
    spreadSheet1.Workbook.Worksheets[0].Cells["B2:C6"].CreateTable(true, "CustomerTable", null);
    ITable table = spreadSheet1.Workbook.Worksheets[0].Tables["CustomerTable"];
    // Apply a built-in table style.
    table.TableStyle = spreadSheet1.Workbook.TableStyles[BuiltInTableStyles.TableStyleDark11];
    
    Copy Code
    ' Create a table.
    spreadSheet1.Workbook.Worksheets(0).Cells("B2:C6").CreateTable(True, "CustomerTable", Nothing)
    Dim table As ITable = spreadSheet1.Workbook.Worksheets(0).Tables("CustomerTable")
    ' Apply a built-in table style.
    table.TableStyle = spreadSheet1.Workbook.TableStyles(BuiltInTableStyles.TableStyleDark11)
    

    Custom Styles

    Custom styles allow you to create your own style to meet specific formatting requirements. You can customize various table elements, such as header rows, column's color, fonts, etc., and use them to format the tables in the worksheet. To apply custom styles, use the TableStyleElementType enumeration of the GrapeCity.Spreadsheet namespace to create a custom style and then apply it to the table.

    The following example code applies a custom style to the table.

    Copy Code
    // Set a custom style for the table.
    ITableStyle style = spreadSheet1.Workbook.TableStyles.Add("CustomStyleBlue");
    // Set the style for the WholeTable element.
    style.TableStyleElements[TableStyleElementType.WholeTable].Font.Italic = true;
    style.TableStyleElements[TableStyleElementType.WholeTable].Font.Color = Color.FromArgb(255, 255, 0);
    style.TableStyleElements[TableStyleElementType.WholeTable].Font.Strikethrough = false;
    style.TableStyleElements[TableStyleElementType.WholeTable].Borders.LineStyle = BorderLineStyle.Dashed;
    style.TableStyleElements[TableStyleElementType.WholeTable].Borders.Color = Color.FromArgb(255, 0, 0);
    style.TableStyleElements[TableStyleElementType.WholeTable].Interior.Color = Color.FromArgb(132, 102, 255);
    // Add a table with the Tables.Add method and apply a custom style.
    spreadSheet1.Workbook.Worksheets[0].Tables.Add(1, 1, 5, 5, YesNoGuess.Yes, "CustomStyleBlue", "TableWithCustomStyle");
    
    Copy Code
    ' Set a custom style for the table.
    Dim style As ITableStyle = spreadSheet1.Workbook.TableStyles.Add("CustomStyleBlue")
    ' Set the style for the WholeTable element.
    style.TableStyleElements(TableStyleElementType.WholeTable).Font.Italic = True
    style.TableStyleElements(TableStyleElementType.WholeTable).Font.Color = Color.FromArgb(255, 255, 0)
    style.TableStyleElements(TableStyleElementType.WholeTable).Font.Strikethrough = False
    style.TableStyleElements(TableStyleElementType.WholeTable).Borders.LineStyle = BorderLineStyle.Dashed
    style.TableStyleElements(TableStyleElementType.WholeTable).Borders.Color = Color.FromArgb(255, 0, 0)
    style.TableStyleElements(TableStyleElementType.WholeTable).Interior.Color = Color.FromArgb(132, 102, 255)
    ' Add a table with the Tables.Add method and apply a custom style.
    spreadSheet1.Workbook.Worksheets(0).Tables.Add(1, 1, 5, 5, YesNoGuess.Yes, "CustomStyleBlue", "TableWithCustomStyle")