The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

How to: Apply a Predefined Style to a Pivot Table

  • 2 min to read

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.

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