[]
        
(Showing Draft Content)

Date Occurring Rule

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 DateOperator property of the IFormatCondition interface.

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

// Adding Date occuring rules
IFormatCondition condition = worksheet.Range["A1:A4"].FormatConditions.Add(FormatConditionType.TimePeriod) as IFormatCondition;
condition.DateOperator = TimePeriods.Yesterday;
condition.Interior.Color = Color.FromArgb(128, 0, 128);

DateTime now = DateTime.Today;
worksheet.Range["A1"].Value = now.AddDays(-2);
worksheet.Range["A2"].Value = now.AddDays(-1);
worksheet.Range["A3"].Value = now;
worksheet.Range["A4"].Value = now.AddDays(1);