[]
        
(Showing Draft Content)

日期相关规则

条件格式功能中的日期相关规则比较单元格或单元格区域中以日期格式输入的值。 可以使用 IFormatCondition 接口的方法添加此规则。

请参阅以下示例代码,将日期相关规则添加到工作表中的单元格区域。

// 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());