Conditional Formatting

Apply formatting rules that change based on cell values.

Basic Example

using DotnetPoi.XSSF.UserModel;

var conditional = new XSSFConditionalFormatting { Sqref = "D4:D6" };
conditional.Rules.Add(new XSSFCFRule
{
    Type = ConditionalFormatType.CellIs,
    Operator = "greaterThan",
    Priority = 1,
    DxfId = -1
});
conditional.Rules[0].Formulas.Add("20");

sheet.AddConditionalFormatting(conditional);

This highlights cells in range D4:D6 where the value is greater than 20.

Conditional Format Types

TypeDescription
CellIsCompare cell value against a formula
FormulaCustom formula expression
ColorScaleColor gradient (2 or 3 colors)
DataBarData bar
IconSetIcon set

Full Runnable Example

See examples/UsageSamples/Program.cs (CreateSpreadsheet):

examples/UsageSamples