Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheets
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Collapse]Tables
      How to: Create a Table
      How to: Apply a Table Style to a Table
      How to: Create, Modify and Delete Table Styles
      How to: Set Default Table Style
    [Expand]Pivot Tables
    [Expand]Printing
    [Expand]Pictures
    [Expand]Charts
    [Expand]Protection
    [Expand]Customization
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Create, Modify and Delete Table Styles

A workbook contains a collection of table styles to format tables (see the How to: Apply a Table Style to a Table example). The IWorkbook.TableStyles property returns the TableStyleCollection object, which specifies the workbook's collection of table styles. By default, this collection contains built-in table styles similar to Microsoft® Excel® and the None table style, which specifies that no formatting should be applied to the table. If you create custom table styles, they are also placed in the workbook's table style collection.

You can do the following to manage the workbook's collection of table styles.

Expanded Modify Existing Table Styles

A table style (TableStyle) consists of a collection of table style elements (TableStyle.TableStyleElements). Each table style element (TableStyleElement) specifies formatting for a particular element of a table. The TableStyleElementType enumerator lists the supported table style element types.

Use properties of the TableStyleElement object to customize borders (TableStyleElement.Borders), fill (TableStyleElement.Fill) and font (TableStyleElement.Font) for the corresponding table element. If you wish to create a style providing striped row or column formatting for a table, customize the FirstRowStripe, SecondRowStripe, FirstColumnStripe or SecondColumnStripe table style elements and set their TableStyleElement.StripeSize property, which specifies the banding rule.

Thus, to modify a table style, follow the steps below.

  1. Access the table style to be changed. To do this, get the corresponding TableStyle object from the IWorkbook.TableStyles collection by the table style name.

    Note

    Built-in table styles cannot be modified. To check whether a table style is built-in or custom, use the TableStyle.BuiltIn property.

  2. Call the TableStyle.BeginUpdate method.

  3. Access the table style element to be modified from the TableStyle.TableStyleElements collection by the corresponding TableStyleElementType enumeration member. Use the TableStyleElement properties to specify the required formatting for the element. If you need to remove existing formatting from the element, use its TableStyleElement.Clear method.

    Repeat this step for all table style elements you wish to modify.

  4. Call the TableStyle.EndUpdate method.

After a table style is changed, the style modifications are automatically applied to all tables that use this style. For details on how a table style is applied to a table and table elements, review the How to: Apply a Table Style to a Table document.

Expanded Create Your Own Custom Table Style

  • Create a New Table Style

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4832.

    This example demonstrates how to create a custom style to format tables.

    1. Add a new table style to the IWorkbook.TableStyles collection by calling the TableStyleCollection.Add method with the table style name passed as a parameter. This method returns the TableStyle object that represents the newly created table style. This object's TableStyle.Name property is set to the specified name. Other settings are identical to the None table style (the default built-in table style that specifies no formatting for a table).

      Note

      Note that table styles have unique names in the collection. To ensure that there is no table style under the specified name in the collection, use the TableStyleCollection.Contains method.

    2. Modify elements of the created table style (TableStyle.TableStyleElements) within the TableStyle.BeginUpdate and TableStyle.EndUpdate paired methods.

    The following image shows the table formatted with the custom table style created by the code above.

  • Duplicate an Existing Table Style

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4909.

    You can create new custom table styles based on existing table styles (for example, based on built-in table styles). To do this, use the TableStyle.Duplicate method. This method creates a copy of the specified style and returns the TableStyle object representing the newly created style. You can use properties of this object to change the style format settings.

    For example, the code snippet below demonstrates how to duplicate an existing style and modify the new style a bit by removing the table header row formatting copied from the source table style.

    The image below shows the TableStyleMedium21 built-in table style and its modified copy.

Expanded Delete Table Styles

To remove a table style from the IWorkbook.TableStyles collection, use the TableStyleCollection.Remove method. After a table style is deleted, all tables to which this style is applied will be formatted with the default style (TableStyleCollection.DefaultStyle).

Note

Built-in table styles cannot be removed. To check whether a table style is built-in or custom, use the TableStyle.BuiltIn property.

Expanded See Also

How would you rate this topic?​​​​​​​