EPPlus 5

Features and technical overview

Pivot table styling using pivot area


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.

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

            //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.Italic = true;

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

            //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.Italic = true;
            styleLabelsForGrandTotal.GrandRow = true;

            //Set the style of the grand total for the data.
            var styleDataForGrandTotal = pivot1.Styles.AddData();
            styleDataForGrandTotal.GrandRow = true;

More detailed samples are available in our sample project or this wiki article.
.NET Core , .NET Framework