[Expand]General Information
[Expand]WinForms Controls
[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
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Charts and Graphics
  [Expand]Mail Merge
   [Expand]Rows and Columns
   [Expand]Import and Export Data
   [Expand]Data Binding
   [Expand]Mail Merge
   [Expand]Formatting Cells
   [Expand]Conditional Formatting
   [Expand]Group Data
   [Expand]Filter Data
   [Collapse]Pivot Tables
     How to: Create a Pivot Table
     How to: Refresh a Pivot Table
     How to: Change a Data Source for a Pivot Table
     How to: Move a Pivot Table
     How to: Clear or Remove a Pivot Table
     How to: Change the PivotTable Layout
     How to: Subtotal Fields in a Pivot Table
     How to: Display or Hide Grand Totals for a Pivot Table
     How to: Format Numbers and Dates in a Pivot Table
     How to: Apply a Predefined Style to a Pivot Table
     How to: Apply a Custom Style to a Pivot Table
     How to: Control Style Options
     How to: Change the Summary Function for a Data Field
     How to: Apply a Custom Calculation to a Data Field
     How to: Create a Calculated Field
     How to: Create a Calculated Item
     How to: Sort Items in a Pivot Table
     How to: Filter Items in a Pivot Table
     How to: Group Items in a Pivot Table
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Apply a Custom Style to a Pivot Table

This example demonstrates how to create a custom style and apply it to a pivot table. By default, the workbook's collection of pivot table styles (TableStyleCollection) contains built-in styles similar to Microsoft® Excel® and the None style, which specifies that no formatting should be applied to the pivot table.

A pivot table style is defined by the TableStyle object, which consists of a collection of table style elements (TableStyle.TableStyleElements). Each table style element (TableStyleElement) specifies formatting for a particular element of a pivot table. The TableStyleElementType enumerator lists the supported table style elements. Use properties of the TableStyleElement object to customize borders (TableStyleElement.Borders), fill (TableStyleElement.Fill) and font (TableStyleElement.Font) for the corresponding element of a pivot table.

To create a custom pivot table style, do the following.

  1. Add a new pivot table style to the IWorkbook.TableStyles collection by calling the TableStyleCollection.Add method. This method returns the TableStyle object that represents the newly created pivot table style.

    Note that you can also create a custom pivot table style based on the existing pivot table style (e.g., a built-in pivot table style). To do this, use the TableStyle.Duplicate method. This method creates a copy of the specified style and returns the TableStyle object representing the created style.

  2. Set the TableStyle.IsPivotStyle property to true and the TableStyle.IsTableStyle property to false to indicate that the created style should be applied only to pivot tables. For the custom styles that are based on the built-in pivot table styles, this step can be skipped since such styles copy appropriate values of these properties from the built-in styles.
  3. Call the TableStyle.BeginUpdate method.
  4. 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.

  5. Call the TableStyle.EndUpdate method.
  6. Apply the created style to the pivot table by using the PivotTable.Style property.

For more details on how to manage the workbook's collection of table and pivot table styles, refer to the How to: Create, Modify And Delete Table Styles topic.

The example below duplicates the built-in pivot table style and modifies the new style by changing formatting characteristics for the entire table, column headers and the grand total row.

The image below illustrates the pivot table appearance when the custom style is applied (the workbook is opened in Microsoft® Excel®).

Expanded See Also

Is this topic helpful?​​​​​​​