# Expression Rule

Learn how to add an expression rule in conditional formatting using DsExcel with a sample code.

## Content





The expression rule in conditional formatting is used to set the expression rule's formula. This rule can be added using the methods of the [IFormatCondition](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IFormatCondition.html) interface.

Refer to the following example code to add expression rule in a worksheet.

```Java
// Adding Expression Rule
Object[][] data = new Object[][] 
{ 
   { 1, 2 }, 
   { 0, 1 }, 
   { 0, 0 }, 
   { 0, 3 }, 
   { 4, 5 } 
};
        
worksheet.getRange("A1:B5").setValue(data);
        
IFormatCondition condition = (IFormatCondition) worksheet.getRange("B1:B5").getFormatConditions().add(FormatConditionType.Expression, FormatConditionOperator.None, "=A1",null);
condition.getInterior().setColor(Color.FromArgb(255, 0, 0));
```