Excel & EPPlus .NET library: Advanced DropDown list validation

末鹿安然 提交于 2019-12-01 02:41:57

问题


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,


回答1:


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;


来源:https://stackoverflow.com/questions/28210584/excel-epplus-net-library-advanced-dropdown-list-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!