EPPlus 5

Features and technical overview

Custom styles for tables, pivot tables and slicers

EPPlus

EPPlus 5.6 adds support for creating and modifying custom table and slicer styles. These styles can be created via the Workbook.Styles object. The following methods are available:

CreateTableStyleFor tables only Returned object will only have style elements that apply to tables
CreatePivotTableStylesFor pivot tables only Returned object will only have style elements that apply to pivot tables
CreateTableAndPivotTableStyleCan be applied to both tables and pivot tables Returned object will have style elements that apply both tables and pivot tables
CreateSlicerStyleFor slicersReturned object will have style elements that apply to slicers.

You can also create your custom style from a built-in table, pivot table or slicer style.

Table styles

This code creates a table style from the built-in table style Dark11 and sets the header row and totals row font to italic. To apply it set the StyleName property on your table

            
                //Create a new custom table style with the built-in style Dark11 as template.
                var customTableStyle = p.Workbook.Styles.CreateTableStyle("MyStyle1", TableStyles.Dark11);

                customTableStyle.HeaderRow.Style.Font.Italic = true;
                customTableStyle.TotalRow.Style.Font.Italic = true;

                tbl.StyleName = "MyStyle1";
            
        

Pivot table styles

Pivot table styles work in the exact same way, but you have style elements that applies to pivot tables.

            
//Create a new custom pivot table style with the built-in style Medium25 as template.
var customPivotTableStyle = p.Workbook.Styles.CreatePivotTableStyle("MyPivotTableStyle", PivotTableStyles.Medium25);

//Alter the font color of the entire table to theme color Text 2
customPivotTableStyle.WholeTable.Style.Font.Color.SetColor(eThemeSchemeColor.Text2);

customPivotTableStyle.HeaderRow.Style.Font.Italic = true;
customPivotTableStyle.TotalRow.Style.Font.Italic = true;

customPivotTableStyle.FirstColumnSubheading.Style.Fill.BackgroundColor.SetColor(Color.LightGreen);
customPivotTableStyle.FirstColumnStripe.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
customPivotTableStyle.FirstColumnStripe.Style.Fill.BackgroundColor.SetColor(Color.WhiteSmoke);
            
        

Slicer style

Slicer styles allows you to style the different slicer style elements:

            
//Create a custom named slicer style that applies users the built-in style Dark4 as template and make some minor modifications.
var customSlicerStyle = p.Workbook.Styles.CreateSlicerStyle(styleName, eSlicerStyle.Dark4);
customSlicerStyle.WholeTable.Style.Font.Name = "Broadway";
customSlicerStyle.HeaderRow.Style.Font.Italic = true;
customSlicerStyle.HeaderRow.Style.Border.Bottom.Color.SetColor(Color.Red);
            
        

Check out this wiki article and sample 27 for more details.
.NET Core , .NET Framework