Skip to main content

How to: Apply a Predefined Style to a Pivot Table

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

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

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

SpreadsheetPivotTable_Examples_ApplyBuiltInStyle

See Also