'Set Row Color Using Epplus

using Epplus how can I set an entire row background color to red? I've got this

int rowNumber = ws.Cells[rowIndex].Value;
ws.Cells[rowIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;

but I'm getting error of

Can not convert from int to string on [rowIndex]

What is the proper way for me to set the row color using C# and epplus?



Solution 1:[1]

Because ws.Cells is an ExcelRange class, when you use [ ] with one parameter you should get a string of Address:

  ws.Cells[string Address]

You can use this with rowIndex and col to reach a cell and then add color:

int col = 1;
int rowIndex = 1;

//in SetColor Method use ColorRgb
ws.Cells[rowIndex, col].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(255, 0, 0));
ws.Cells[rowIndex, col].Style.Font.Bold = true;

If you want to modify the color to multiple rows instead of a cell, use this:

ws.Cells[int FromRow, int FromCol, int ToRow, int ToCol]

With this, you can reach all of first twenty columns and set the color for them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney