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?
CodePudding user response:
Because ws.Cells is ExcelRange Class so when you use [ ] with 1 parameter you should get it an string of address.
ws.Cells[string Address]
You Can use this with rowIndex and col to reach 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 not Cell use this:
ws.Cells[int FromRow, int FromCol, int ToRow, int ToCol]
with this you can reach all of first 20 columns and set color for them.