Syncfusion Feedback

Trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

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.

Data Validation Code Example

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);

Key features of data validation

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.

Text length validation

Users can restrict the text length in a cell, ensuring data meets defined character limits and preventing errors in the worksheet.

Time validation

Restrict the entry of time values within a specified range, ensuring data accuracy when working with time-related data.

List validation

Create a dropdown list of predefined values, allowing selection from specific options to ensure consistency and reduce input errors.

Number validation

Restrict the cell input to numbers within a specified range, ensuring that only valid numerical values are entered for accurate data analysis.

Date validation

Restrict the entry of dates to within a specified range, to maintain data accuracy when dealing with date-sensitive information.

Custom validation

Define custom rules using formulas to validate data entry, providing flexibility in enforcing specific criteria that fit your needs.

Explore Data Validation References

Discover valuable resources from our blog and knowledge base articles to enhance your efficiency in using data validation.

Implementing data validation in Excel cells using C#.

Blog

Implementing Data Validation in Excel Cells Using C#

Create list data validation in C# and VB.NET.

Knowledge base

How to create list data validation for more than 255 characters in C# VB.NET?

Set datarange for validation from another sheet in C# and VB.NET.

Knowledge base

How to set DataRange for data validation from a different sheet using C# VB.NET?

Protect Excel columns based on dropdown value.

Knowledge base

How to protect Excel columns based on a drop down value from a cell?

Create dependent multi select dropdowns in Excel using C#.

Knowledge base

How to create multiple dependent dropdown lists with multi-selection in an Excel document using C#

Syncfusion .NET Excel Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.

Frequently Asked Questions

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.

Our Customers Love Us

Having an excellent set of tools and a great support team, Syncfusion® reduces customers’ development time.
Here are some of their experiences.

Rated by users across the globe

Want to create, View, and edit Excel files in C# or VB.NET?

Start a free 30-day evaluation today!
DOWNLOAD FREE TRIAL

No credit card required.

Mobile Free Evaluation Section

Awards

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.

Scroll up icon