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

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

This is working well.

Dim objExcel As New ExcelPackage
Dim Sheet As ExcelWorksheet = objExcel.Workbook.Worksheets.Add("SheetName")
Sheet.Cells["A1"].Style.Fill.PatternType = Style.ExcelFillStyle.Solid
Sheet.Cells["A1"].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(170, 170, 170))

You are not obliged to translate a hexadecimal CSS color formula: You can simply put "0X" as a header of that number, which makes it an integer expression:

    var couleur = System.Drawing.Color.FromArgb(OXB7DEF8);
    Sheet.Cells["A1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
    Sheet.Cells["A1"].Style.Fill.BackgroundColor.SetColor(couleur);

Tags:

C#

Openxml

Epplus