Excel Data Validation with ExcelPackage

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

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

Regards

Aug 15, 2011 at 10:17 AM

Hi,

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.

TIA,

guapo

Sep 20, 2011 at 7:36 PM
Edited Sep 20, 2011 at 7: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.

 

Ted