Rubix_Revenge Rubix_Revenge - 1 year ago 179
C# Question

Epplus: How to apply a style from the Excel Style Gallery to an ExcelRange

The screenshot shows a scenario for a dataset exported by Epplus to a fresh Excel file (file type *.xlsx).

In this scenario, I'd like to apply the "Bad" Style in the Excel Style Gallery to Cell E1. How could I do this programatically in Epplus?

Screenshot of example scenario

I have looked through the instructional documents I was able to find, here and here. I have not yet found an example showing how to apply an Excel style from the Style Gallery to an Excel Range.

Here is what I have so far.

private void FormatDataTable(ExcelWorksheet worksheet)
// How do I apply the "Bad" style to this range?
var range = worksheet.Cells["E1"];

Answer Source

As far as I know it's no way. But always exists way around

var cell = worksheet.Cells["E1"];
cell.Style.Font.Name = "Calibri";
cell.Style.Font.Size = 11;
cell.Style.Fill.PatternType = ExcelFillStyle.Solid;

This should make the trick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download