EPPlus 5/6/7

Features and technical overview

Pivot table styling using pivot area

EPPlus

EPPlus 5.6 adds support for styling pivot tables using pivot areas. With this feature you can style different parts of the table as well as individual items in the table.

Pivot table styling

This image is the output of our first styling sample.

Pivot table styling
        
var pivot1 = pck.Workbook.Worksheets["PivotSimple"].PivotTables[0];
//First add a style that sets the font and color for the entire pivot table.
var styleWholeTable = pivot1.Styles.AddWholeTable();
styleWholeTable.Style.Font.Name = "Times New Roman";
styleWholeTable.Style.Font.Color.SetColor(eThemeSchemeColor.Accent2);

//Adds new style for all labels in the pivot table. Later added styles will override earlier added styles.
var styleLabels = pivot1.Styles.AddAllLabels();
styleLabels.Style.Font.Color.SetColor(eThemeSchemeColor.Accent4);
styleLabels.Style.Font.Italic = true;

//This style sets the colors for the labels of the first row field.
var styleLabelsForRowField = pivot1.Styles.AddLabel(pivot1.RowFields[0]);
styleLabelsForRowField.Style.Font.Color.SetColor(eThemeSchemeColor.Text1);

//This style sets the color and font italic for the grand row of the first row field.
var styleLabelsForGrandTotal = pivot1.Styles.AddLabel(pivot1.RowFields[0]);
styleLabelsForGrandTotal.Style.Font.Color.SetColor(Color.Red);
styleLabelsForGrandTotal.Style.Font.Italic = true;
styleLabelsForGrandTotal.GrandRow = true;

//Set the style of the grand total for the data.
var styleDataForGrandTotal = pivot1.Styles.AddData();
styleDataForGrandTotal.Style.Font.Color.SetColor(eThemeSchemeColor.Accent6);
styleDataForGrandTotal.GrandRow = true;
        
        

See also