Search code examples
c#asp.net-mvcepplus

Set color to group of cells in excel


Currently we are using following code to set the color in cells,

worksheet.Cells[18, 1].Style.Fill.BackgroundColor.SetColor(Constants.highlightingColor);

Is there any way to set color to group of cells ? Like we set color in group of elements in css using class name.


Solution

  • If you are looking to set a range of cells at once, you can simply use the Cells object indexer overloads. Something like this:

    worksheet.Cells[18,1,28,11].Style.Fill.BackgroundColor.SetColor(Constants.highlightingColor);
    

    Will start at the Cell at row 18 col 1 and go to the Cell at row 28 col 11 and set all background colors.