Search code examples
c#epplus

EPPlus Set background color of entire worksheet


Using EPPlus, I understand that you can set the background color of individual cells, or a range of cells as follows:

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

Is there any way to set the background color of the entire worksheet? Or is this just a case of setting a very wide range of cells?

So for example I could do:

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

I'm not sure if there is a performance concern doing this? I tried it with "A1:ZZ100000", it just hung.


Solution

  • Just use cells directly without specifying address range:

    ws.Cells.Style.Fill.PatternType = ExcelFillStyle.Solid;
    ws.Cells.Style.Fill.BackgroundColor.SetColor(Color.White);
    

    Tested it, it takes no time.