How to set data validation for Date?
Use the following code snippets to set data validation for date.
C#
// Data Validation for Date
IDataValidation validation = sheet.Range["A5"].DataValidation;
sheet.Range["A5"].Text = "Enter the Date";
validation.AllowType = ExcelDataType.Date;
validation.CompareOperator = ExcelDataValidationComparisonOperator.Between;
validation.FirstDateTime = new DateTime(2003, 5, 10);
validation.SecondDateTime = new DateTime(2004, 5, 10);
validation.ShowErrorBox = true;
validation.ErrorBoxText = "Enter a value between 10/5/2003 and 10/5/2004";
validation.ErrorBoxTitle = "ERROR";
validation.PromptBoxText = "Data Validation using Condition for Date";
validation.ShowPromptBox = true;
VB
' Data Validation for Date
Dim validation2 As IDataValidation = sheet.Range("A5").DataValidation
sheet.Range("A5").Text = "Enter the Date"
validation2.AllowType = ExcelDataType.Date
validation2.CompareOperator = ExcelDataValidationComparisonOperator.Between
validation2.FirstDateTime = New DateTime(2003, 5, 10)
validation2.SecondDateTime = New DateTime(2004, 5, 10)
validation2.ShowErrorBox = True
validation2.ErrorBoxText = "Enter a value between 10/5/2003 and 10/5/2004"
validation2.ErrorBoxTitle = "ERROR"
validation2.PromptBoxText = "Data Validation using Condition for Date"
validation2.ShowPromptBox = True
Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through formulas, adding charts in worksheets or workbooks, organizing and analyzing data through tables and pivot tables, appending multiple records to a worksheet using template markers, and most importantly, PDF and image conversions, etc., with code examples.
Refer here to explore the rich set of Syncfusion Essential XlsIO features.
Note:
Starting with v16.2.0.x, if you reference Syncfusion assemblies from the trial setup or from the NuGet feed, include a license key in your projects. Refer to this link to learn about generating and registering a Syncfusion license key in your application to use the components without a trial message.
Conclusion:
I hope you enjoyed learning about how to set data validation for a date in XlsIO.
You can refer to our XlsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.
If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.
If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums or feedback portal. We are always happy to assist you!