Reputation: 363
I am trying to write Excel file from datatable with VB.NET. I am able to achieve few excel operations also. Now I want to colour a row based on cell value of a particular column (Col-4 for example). Here is my Excel file -
Looking some guidance to achieve this.
Upvotes: 1
Views: 7424
Reputation: 4849
I suggest you add conditional formatting. For example:
var workbook = new XLWorkbook();
var ws = workbook.AddWorksheet("Sheet1");
ws.FirstCell().SetValue(1)
.CellBelow().SetValue(1)
.CellBelow().SetValue(2)
.CellBelow().SetValue(3)
.CellBelow().SetValue(4);
ws.RangeUsed().AddConditionalFormat().WhenBetween(2, 3)
.Fill.SetBackgroundColor(XLColor.Red);
Reference: https://github.com/ClosedXML/ClosedXML/wiki/Conditional-Formatting
Upvotes: 3