I have an asp.net application that is exporting data to excel. I need to shade the cells in the excel file.
I would like the 1st row to have a darkgray background. The second row to have a light graybackground and the 3rd row to be regular white. Then loop (darkgray, lightgray, white etc).
Currently, using EPPlus, this is my code:
Dim colIndex As Integer = 1
Dim rowIndex As Integer = 1
Dim xlRow = excelWorksheet.Row(rowIndex)
Dim xlCell = excelWorksheet.Cells(rowIndex, colIndex)
Dim CellFill = xlCell.Style.Fill
Dim RowFill = xlRow.Style.Fill
CellFill.PatternType = ExcelFillStyle.Solid
RowFill.PatternType = ExcelFillStyle.Solid
RowFill.BackgroundColor.SetColor(Drawing.Color.DarkGray)
This would be very long and complex if I was to code for every cell. How can I make this into a loop ? Ideally, I would like a range of columns (example Column A: Column E)
Not tested but should give you the clue: