Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel & EPPlus .NET library: Advanced DropDown list validation

In Epplus, when we create a DropDown list for some cells in excel file, then user put a value which is not part of the list, the cell show a message says: value must match one of the listed items.

Instead of this message, Is it possible to prevent the user to put a value which is not part of the drop down list?

Thanks in advance,

like image 662
I3i0 Avatar asked Jan 29 '15 09:01

I3i0


People also ask

What's Excel used for?

Microsoft Excel enables users to format, organize and calculate data in a spreadsheet. By organizing data using software like Excel, data analysts and other users can make information easier to view as data is added or changed. Excel contains a large number of boxes called cells that are ordered in rows and columns.

What is Excel formula?

What is Excel Formula? In Microsoft Excel, a formula is an expression that operates on values in a range of cells. These formulas return a result, even when it is an error. Excel formulas enable you to perform calculations such as addition, subtraction, multiplication, and division.

What is basic Excel?

You put data in your cells and group them in rows and columns. That allows you to add up your data, sort and filter it, put it in tables, and build great-looking charts. Let's go through the basic steps to get you started.


1 Answers

I did it with the following code:

//ExcelWorksheet ws
var validation = ws.DataValidations.AddListValidation(cell.Address);
//Error handling
validation.ShowErrorMessage = true;
validation.ErrorStyle = ExcelDataValidationWarningStyle.stop;
validation.ErrorTitle = "Error";
validation.Error = "Error Text";
// sheet with a name : DropDownLists 
// from DropDownLists sheet, get values from cells: !$A$1:$A$10
var formula = "=DropDownLists!$A$1:$A$10";
//Applying Formula to the range
validation.Formula.ExcelFormula = formula;
like image 108
I3i0 Avatar answered Nov 08 '22 15:11

I3i0