You can change the validation rule for a 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.
C# |
Copy Code |
---|---|
//Add validation worksheet.Range["A1:A2"].Validation.Add(ValidationType.Date, ValidationAlertStyle.Stop, ValidationOperator.Between, new TimeSpan(13, 30, 0), new TimeSpan(18, 30, 0)); //Modify validation. worksheet.Range["A1:A2"].Validation.Type = ValidationType.Time; worksheet.Range["A1:A2"].Validation.AlertStyle = ValidationAlertStyle.Stop; worksheet.Range["A1:A2"].Validation.Operator = ValidationOperator.Between; worksheet.Range["A1:A2"].Validation.Formula1 = new TimeSpan(13, 30, 0).TotalDays.ToString(); worksheet.Range["A1:A2"].Validation.Formula2 = new TimeSpan(18, 30, 0).TotalDays.ToString(); |