Back to Devexpress

How to: Apply a Predefined Style to a Pivot Table

officefileapi-118505-spreadsheet-document-api-examples-pivot-tables-how-to-apply-a-predefined-style-to-a-pivot-table.md

latest2.4 KB
Original Source

How to: Apply a Predefined Style to a Pivot Table

  • Sep 19, 2023

The example below demonstrates how to change the appearance of the existing pivot table using one of the predefined pivot table styles. To apply a style, assign the corresponding TableStyle object to the PivotTable.Style property. Access the required pivot table style from the IWorkbook.TableStyles collection by its ID (a member of the BuiltInPivotStyleId enumeration).

Note that you can also create your own style and apply it to a pivot table, as shown in the How to: Apply a Custom Style to a Pivot Table example.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report1"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Set the pivot table style.
pivotTable.Style = workbook.TableStyles[BuiltInPivotStyleId.PivotStyleDark7];
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report1")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")
' Set the pivot table style.
pivotTable.Style = workbook.TableStyles(BuiltInPivotStyleId.PivotStyleDark7)

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

See Also

How to: Control Style Options in a Pivot Table

How to: Apply a Custom Style to a Pivot Table