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

    The unique rule in conditional formatting is applied to check whether the value entered in a cell is a unique value in that particular range. This is possible only when the duplication option is set to false. To check for the duplicate values, the duplicate rule is applied separately.

    Unique rule can be added using the methods of the IUniqueValues interface.

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

    Java
    Copy Code
    // Adding Unique Rule
    Object[][] data = new Object[][] 
    { 
        { 1 }, 
        { 2 }, 
        { 1 }, 
        { 3 }, 
        { 4 } 
    };
    worksheet.getRange("A1:A5").setValue(data);
    
    IUniqueValues condition2 = worksheet.getRange("A1:A5").getFormatConditions().addUniqueValues();
    condition2.setDupeUnique(DupeUnique.Unique);
    condition2.getFont().setName("Arial");