Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EPPlus Set background color of entire worksheet

Tags:

c#

epplus

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.

like image 689
Jacques Avatar asked Oct 24 '25 15:10

Jacques


1 Answers

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.

like image 106
Yahya Hussein Avatar answered Oct 26 '25 05:10

Yahya Hussein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!