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

    The date occurring rule in conditional formatting feature compares the values entered in date format in the cells or a range of cells. This rule can be added using the methods of the IFormatCondition interface.

    Refer to the following example code to add date occurring rule to a range of cells in a worksheet.

    Java
    Copy Code
    // Adding Date Occuring Rules
    Workbook workbook = new Workbook();
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    IFormatCondition condition = (IFormatCondition)worksheet.getRange("A1:A4").getFormatConditions().add(FormatConditionType.TimePeriod);
    condition.setDateOperator(TimePeriods.Yesterday); 
    condition.getInterior().setColor(Color.FromArgb(128,0,128));
    
    Calendar now=Calendar.getInstance();
            
    worksheet.getRange("A1").setValue(now.getTime());
    now.add(Calendar.DAY_OF_YEAR, -1);
    worksheet.getRange("A2").setValue(now.getTime());
    now.add(Calendar.DAY_OF_YEAR, -1);
    worksheet.getRange("A3").setValue(now.getTime());
    now.add(Calendar.DAY_OF_YEAR, 3);
    worksheet.getRange("A4").setValue(now.getTime());