Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom BackgroundColor of a Excel sheet cell using epplus c#

Tags:

c#

epplus

openxml

The problem:

I am using EEPlus.

I am stuck at applying a hex color code, e.g. #B7DEE8, for a cell in my Excel sheet.

I got the following (working) code:

ws.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.Solid; ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(Color.Gray); 

But I need something like the following:

ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor("#B7DEE8"); 

So my question is: is it possible to use hex color codes with EEPlus? If so, how can I do that?

like image 585
Hakuna Matata Avatar asked Jun 08 '13 10:06

Hakuna Matata


People also ask

How do I change the background color on EPPlus?

Fill. BackgroundColor. SetColor("#B7DEE8");

What is the use of EPPlus?

EPPlus is a very helpful open-source 3rd party DLL for writing data to excel. EPPlus supports multiple properties of spreadsheets like cell ranges, cell styling, charts, pictures, shapes, comments, tables, protection, encryption, pivot tables, data validation, conditional formatting, formula calculation, etc.


1 Answers

Try this

Color colFromHex = System.Drawing.ColorTranslator.FromHtml("#B7DEE8"); ws.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.Solid; ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(colFromHex); 
like image 138
Yograj Gupta Avatar answered Oct 08 '22 09:10

Yograj Gupta