Conditional Formatting Help

Jun 8, 2012 at 9:59 AM

Good day,

I want to use conditional formatting to format a cell if the value is either Fail or Pass. I tried the following:

 

InitializeWorkbook();
ISheet sheet1 = hssfworkbook.CreateSheet("Test");
ISheetConditionalFormatting hscf = sheet1.SheetConditionalFormatting;

IConditionalFormattingRule cfrFail = hscf.CreateConditionalFormattingRule(
    ComparisonOperator.EQUAL, "Fail");

IConditionalFormattingRule cfrPass = hscf.CreateConditionalFormattingRule(
    ComparisonOperator.EQUAL, "Pass");

IConditionalFormattingRule[] rules = { cfrPass, cfrFail };

IPatternFormatting pfRed = cfrFail.CreatePatternFormatting();
pfRed.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;

IPatternFormatting pfGreen = cfrPass.CreatePatternFormatting();
pfGreen.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.GREEN.index;

CellRangeAddress[] regions = {
    new CellRangeAddress(0, 65535,0,1)
};

hscf.AddConditionalFormatting(regions, rules);

 

It gives a run time error: "Unhandled Exception: NPOI.SS.Formula.FormulaParseException: Specified named range 'Fail' does not exist in the current workbook."

So my question is, how do I test for a string value?

Thank you