How to set color or background with "excelpackage"

26,587

Try something along these lines (Taken from the EPPlus sample files provided):

using (var range = worksheet.Cells[1, 1, 1, 5]) 
    {
        range.Style.Fill.PatternType = ExcelFillStyle.Solid;
        range.Style.Fill.BackgroundColor.SetColor(Color.DarkBlue);
    }
Share:
26,587
Sergey
Author by

Sergey

I am .NET developer (C#). ASP.NET MVC 3, Razor, JavaScript, JQuery, Mobile development, T-SQL (MS SQL Server), HTML 5, CSS 3. My portfolio and contact information on my home page.

Updated on July 16, 2020

Comments

  • Sergey
    Sergey almost 4 years

    I use this package: ExcelPackage though I can't figure out how to set the background color for the cell. I tried to use this:

    ws.Cells["A1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
    

    But it shows that the properties are not found.

    enter image description here

    Sounds like I should use something similar to this:

    worksheet.Cell(5, columnIndex + 1).Style = "background-color: red";
    

    But I am not sure how it works and I couldn't find the tutorial for it. Please help.