Document Solutions for Excel, Java Edition | Document Solutions
Features / Conditional Formatting / Expression Rule
In This Topic
    Expression Rule
    In This Topic

    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 interface.

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

    Java
    Copy Code
    // 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));