Skip to content

Pivot table styling via Pivot Areas

Jan Källman edited this page Mar 8, 2021 · 12 revisions

Pivot tables can be styled with using special conditions rather than styling via the A1C1 notation. EPPlus from version 5.6 supports this custom styling.

Samples

Styling the entire pivot table

A pivot area defines an area within the pivot table. This example adds a style for the whole table and sets the font to Times New Roman and the font color to Accent2.

var styleWholeTable = pivotTable1.Styles.AddWholeTable();
styleWholeTable.Style.Font.Name = "Times New Roman";
styleWholeTable.Style.Font.Color.SetColor(eThemeSchemeColor.Accent2);

You can also specify a specific style for all Labels...

var styleLabels = pivot1.Styles.AddAllLabels();
styleLabels.Style.Font.Color.SetColor(eThemeSchemeColor.Accent4);
styleLabels.Style.Font.Italic = true;

...or all data

var styleData = pivot1.Styles.AddAllData();
styleData.Style.Font.Name = "Arial";
styleLabels.Style.Font.Bold = true;

Styling other parts of the pivot table.

You can also add styles for other parts of the pivot table like the button fields, top left and right area.

//Styles the area to the left of the column axis button field.
var topLeft = pivot2.Styles.AddTopStart();
topLeft.Style.Fill.BackgroundColor.SetColor(Color.Green);

//Styles the area to the right of the the column axis button field label. 
var topRight = pivot2.Styles.AddTopEnd();
topRight.Style.Fill.BackgroundColor.SetColor(Color.Red);

//Here we only want to style a part of the top right area. 
//We use the Offset property that uses the A1C1 address notation starting from the cell to the right as A1. 
//B1 here will be the second cell to the right. You can also use multiple cells references, like A1:B1
var topRightOffset1 = pivot2.Styles.AddTopEnd("B1");
topRightOffset1.Style.Border.BorderAround(ExcelBorderStyle.Dotted, eThemeSchemeColor.Text1);

Styling areas using with fields and conditions.

EPPlus wiki

Versions

Worksheet & Ranges

Styling

Import/Export data

Formulas and filters

Charts & Drawing objects

Tables & Pivot Tables

VBA & Protection

Clone this wiki locally