I3i0
I3i0

Reputation: 1191

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,

Upvotes: 8

Views: 7375

Answers (1)

I3i0
I3i0

Reputation: 1191

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;

Upvotes: 11

Related Questions