Excel Data Validation with ExcelPackage

Topics: Developer Forum, Project Management Forum, User Forum
Jan 18, 2010 at 9:45 AM

how can we do to replicate with Excel Package what we normaly do in Excell with the Data Validation ?


Aug 15, 2011 at 11:17 AM


any update from this thread?

how can i create a list/dropdown list use to validate cell range input?

for example, only RED, BLUE and YELLOW are valid to enter in column B. and must have a dropdown list to select valid values (the RED, BLUE and YELLOW). if the user entered value aside from the list, must have a message box informing him/her for invalid data.

any suggestion or C# code snippet will be appreciated.



Sep 20, 2011 at 8:36 PM
Edited Sep 20, 2011 at 8:38 PM

With the caveat that this doesn't actually work (see bug item at here for more)...


OfficeOpenXml.DataValidation.Contracts.IExcelDataValidationList valid = 
     worksheet.Cells[left, top, right, bottom].DataValidation.AddListDataValidation(); valid.AllowBlank = true; valid.ShowErrorMessage = true; valid.ShowInputMessage = true; valid.Formula.Values.Add("RED"); valid.Formula.Values.Add("BLUE"); valid.Formula.Values.Add("YELLOW");

As I said, this should work but currently my Excel2007 removes the validation info as "invalid" for some reason.  I'm trying to identify the problem since I really need this too work.