static void AddRangeConditionalFormatting(IWorkbook workbook) { workbook.Calculate(); workbook.BeginUpdate(); try { Worksheet worksheet = workbook.Worksheets["cfBooks"]; workbook.Worksheets.ActiveWorksheet = worksheet; #region #RangeConditionalFormatting // Create the rule to identify values below 7 and above 19 in cells F2 through F15. RangeConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddRangeConditionalFormatting(worksheet["$F$2:$F$15"], ConditionalFormattingRangeCondition.Outside, "7", "19"); // Specify formatting options to be applied to cells if the condition is true. // Set the background color to yellow. cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xFA, 0xF7, 0xAA); // Set the font color to red. cfRule.Formatting.Font.Color = Color.Red; #endregion #RangeConditionalFormatting // Add an explanation to the created rule. CellRange ruleExplanation = worksheet.Range["A17:G18"]; ruleExplanation.Value = "Identify book prices that are below $7 and above $19."; } finally { workbook.EndUpdate(); } }
static void AddRangeConditionalFormatting(IWorkbook workbook) { #region #RangeConditionalFormatting Worksheet worksheet = workbook.Worksheets["cfBooks"]; workbook.Worksheets.ActiveWorksheet = worksheet; RangeConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddRangeConditionalFormatting(worksheet["$G$5:$G$18"], ConditionalFormattingRangeCondition.Outside, "7", "19"); cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xFA, 0xF7, 0xAA); cfRule.Formatting.Font.Color = Color.Red; worksheet["B2"].Value = "In the report below identify price values that are less than $7 and greater than $19."; worksheet.Visible = true; #endregion #RangeConditionalFormatting }