[]
        
(Showing Draft Content)

修改验证

可以使用以下两种方法之一修改单元格区域的验证规则:

请参阅以下示例代码,了解如何修改应用于工作表中某个单元格或某个单元格区域的现有验证规则。

Calendar time1 = new GregorianCalendar(1899, 11, 30, 13, 30, 0);
Calendar time2 = new GregorianCalendar(1899, 11, 30, 18, 30, 0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");
        
// Add Validation
worksheet.getRange("A1:A2").getValidation().add(ValidationType.Date, ValidationAlertStyle.Stop,
        ValidationOperator.Between, simpleDateFormat.format(time1.getTime()),
        simpleDateFormat.format(time2.getTime()));

// Modify validation.
worksheet.getRange("A1:A2").getValidation().setType(ValidationType.Time);
worksheet.getRange("A1:A2").getValidation().setAlertStyle(ValidationAlertStyle.Warning);
worksheet.getRange("A1:A2").getValidation().setOperator(ValidationOperator.NotBetween);