B. Clay Shannon B. Clay Shannon - 10 months ago 292
C# Question

How can I assign a color to a font in EPPlus?

I can set the background color of a cell or range of cells like so:

rowRngprogramParamsRange.Style.Fill.PatternType = ExcelFillStyle.Solid;

I have not been able to set the font color, though. I tried this:

rowRngprogramParamsRange.Style.Font.Color = Color.Red;

...which failed to compile with two err msgs: the first, that I cannot assign System.Drawing.Color to OfficeOpenXml.Style.ExcelColor, and the second that the property is readonly anyway.

Just for grin and bear its, I tried casting the value:

rowRngprogramParamsRange.Style.Font.Color = (OfficeOpenXml.Style.ExcelColor)Color.Red;

...and I now get, "Cannot convert type 'System.Drawing.Color' to 'OfficeOpenXml.Style.ExcelColor'"

Most everything in EPPlus is pretty easy, certainly easier than Excel Interop, but this one has me baffled. How does one assign a color to a font for a range in EPPlus?


It's safe to assume Style.Fill.BackgroundColor and Style.Font.Color are both of type ExcelColor, so just use the same SetColor() method you used to set the background color.