Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set color or background with "excelpackage"

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.

like image 257
Sergey Avatar asked Jun 17 '13 20:06

Sergey


People also ask

Where do you put bgcolor to apply a color in a specific cell?

Select the cell or range of cells you want to format. Click Home > Format Cells dialog launcher, or press Ctrl+Shift+F. On the Fill tab, under Background Color, pick the color you want.


1 Answers

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);
    }
like image 121
John Bustos Avatar answered Oct 21 '22 08:10

John Bustos