Conditional Formatting Cell Values
Output: ConditionalFormattingCellValue.xlsx
public void Run()
{
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
worksheet.Columns[0].WidthCharacters = 40;
worksheet.Columns.SetWidthCharacters("B", "F", 5);
worksheet.GetRange("B1:F1").SetValue(new[] {1, 2, 3, 4, 5});
worksheet.GetRange("B2:F2").SetValue(new[] {1, 2, 3, 4, 5});
worksheet.GetRange("B3:F3").SetValue(new[] {1, 2, 3, 4, 5});
worksheet.GetRange("B4:F4").SetValue(new[] {1, 2, 3, 4, 5});
worksheet.GetRange("B5:F5").SetValue(new[] {1, 2, 3, 4, 5});
worksheet.GetRange("B6:F6").SetValue(new[] {1, 2, 3, 4, 5});
worksheet.GetRange("B7:F7").SetValue(new[] {1, 2, 3, 4, 5});
worksheet.GetRange("B8:F8").SetValue(new[] {1, 2, 3, 4, 5});
worksheet["A1"].Value = "Cell Value between 2 and 4";
var ruleB1 = worksheet.ConditionalFormattings.AddCellValue("B1:F1", ConditionalFormattingOperator.Between, 2, 4);
ruleB1.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);
worksheet["A2"].Value = "Cell Value not between 2 and 4";
var ruleB2 = worksheet.ConditionalFormattings.AddCellValue("B2:F2", ConditionalFormattingOperator.NotBetween, 2, 4);
ruleB2.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);
worksheet["A3"].Value = "Cell Value equal to 3";
var ruleB3 = worksheet.ConditionalFormattings.AddCellValue("B3:F3", ConditionalFormattingOperator.Equal);
ruleB3.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);
worksheet["A4"].Value = "Cell Value not equal to 3";
var ruleB4 = worksheet.ConditionalFormattings.AddCellValue("B4:F4", ConditionalFormattingOperator.NotEqual);
ruleB4.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);
worksheet["A5"].Value = "Cell Value greater than 3";
var ruleB5 = worksheet.ConditionalFormattings.AddCellValue("B5:F5", ConditionalFormattingOperator.GreaterThan);
ruleB5.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);
worksheet["A6"].Value = "Cell Value less than 3";
var ruleB6 = worksheet.ConditionalFormattings.AddCellValue("B6:F6", ConditionalFormattingOperator.LessThan);
ruleB6.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);
workbook.SaveAs("ConditionalFormattingCellValue.xlsx");
}