Excel& EPPlus .NET库:Advanced DropDown列表验证 [英] Excel & EPPlus .NET library: Advanced DropDown list validation

查看:218
本文介绍了Excel& EPPlus .NET库:Advanced DropDown列表验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Epplus中,当我们为excel文件中的某些单元格创建一个DropDown列表时,用户放置一个不属于列表的值,该单元格显示一条消息:值必须与列出的项目匹配。 p>

而不是这个消息,是否可以阻止用户放置一个不属于下拉列表的值?



提前感谢

解决方案

我使用以下代码:

  // ExcelWorksheet ws 
var validation = ws.DataValidations.AddListValidation(cell.Address);
validation.ShowErrorMessage = true;
validation.ErrorStyle = ExcelDataValidationWarningStyle.stop;
validation.ErrorTitle =Error;
validation.Error =Error Text;
//具有名称的工作表:DropDownLists
//从DropDownLists工作表中,从单元格获取值:!$ A $ 1:$ A $ 10
var formula == DropDownLists!$ A $ 1: $ A $ 10
//将公式应用于范围
validation.Formula.ExcelFormula = formula;


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,

解决方案

I did it with the following code:

//ExcelWorksheet ws
var validation = ws.DataValidations.AddListValidation(cell.Address);
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;

这篇关于Excel& EPPlus .NET库:Advanced DropDown列表验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆