You can modify the validation rule for a cell range by using either of the two ways described below:
Refer to the following example code to know how you can modify an existing validation rule applied to a cell or a range of cells in a worksheet.
Java |
Copy Code |
---|---|
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); |