The Syncfusion .NET Excel library (XlsIO) offers comprehensive support for data validation. It enables you to enforce predefined rules that restrict the type and format of data that users can enter into a cell.
This example code shows how to add dropdown list validation toan Excel worksheet using the Syncfusion .NET Excel library with just a few lines of C# code.
- // Initialize Excel engine and application
- using ExcelEngine excelEngine = new ExcelEngine();
- IApplication application = excelEngine.Excel;
- application.DefaultVersion = ExcelVersion.Xlsx;
- // Create a workbook and worksheet
- IWorkbook workbook = application.Workbooks.Create(1);
- IWorksheet worksheet = workbook.Worksheets[0];
- // Data validation for lists
- IDataValidation listValidation = worksheet.Range["C3"].DataValidation;
- worksheet.Range["C1"].Text = "Data Validation List in C3";
- worksheet.Range["C1"].AutofitColumns();
- listValidation.ListOfValues = new string[] { "ListItem1", "ListItem2", "ListItem3" };
- // Shows the error message
- listValidation.ErrorBoxText = "Choose the value from the list";
- listValidation.ErrorBoxTitle = "ERROR";
- listValidation.PromptBoxText = "Data validation for list";
- listValidation.IsPromptBoxVisible = true;
- listValidation.ShowPromptBox = true;
- // Save the Excel document
- using FileStream outputStream = new FileStream("ListValidation.xlsx", FileMode.Create, FileAccess.Write);
- workbook.SaveAs(outputStream);
Discover how data validation in the Excel Library enables control over data entry, ensuring that input meets defined criteria to maintain accuracy and consistency within Excel worksheets.
Users can restrict the text length in a cell, ensuring data meets defined character limits and preventing errors in the worksheet.
Restrict the entry of time values within a specified range, ensuring data accuracy when working with time-related data.
Create a dropdown list of predefined values, allowing selection from specific options to ensure consistency and reduce input errors.
Restrict the cell input to numbers within a specified range, ensuring that only valid numerical values are entered for accurate data analysis.
Restrict the entry of dates to within a specified range, to maintain data accuracy when dealing with date-sensitive information.
Define custom rules using formulas to validate data entry, providing flexibility in enforcing specific criteria that fit your needs.
Discover valuable resources from our blog and knowledge base articles to enhance your efficiency in using data validation.
Knowledge base
Knowledge base
Knowledge base
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
Yes, you can set text length data validation using the Syncfusion Excel library. This functionality lets users to specify the length of text allowed in a cell or range of cells within an Excel workbook.
Yes. You can select any cell range within the workbook to create list validation.
Yes. You can customize the title of the error box dialogue in data validation.
Yes. You can set the cell data validation to use only whole numbers so that it accepts only whole number values.
Yes, you can use list validation to create a dropdown in the Excel document with a predefined range of values.
Yes. You can provide an input message to the user as a tooltip in the Excel cells.
Yes. You can use any Excel function in the formula to validate the cell value.
Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.