码迷,mamicode.com
首页 > 其他好文 > 详细

Excel导出,添加有效性

时间:2019-10-16 11:11:30      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:++   字符   下拉列表   show   eva   rbo   exp   tab   tco   

#region  添加有效性

DataTable dt = LAbll.LogisticsAccounts(DeptId); //查数据

if (dt.Rows.Count < 20) //有效性字符限制255,一组字符12加分割符=13
{
  string[] strs = {};
  for (int l = 0; l < dt.Rows.Count; l++)
  {
    string[] sigle = { "" + dt.Rows[l]["XXX"].ToString() + "" };
    strs = strs.Concat(sigle).ToArray();
  }
  XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheetHead);
  XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)dvHelper.CreateExplicitListConstraint(strs);
  CellRangeAddressList addressList = new CellRangeAddressList(1, 1, 3, 3); //(开始行,结束行,开始列,结束列)
  XSSFDataValidation validation = (XSSFDataValidation)dvHelper.CreateValidation(dvConstraint, addressList);
  validation.CreatePromptBox("输入提示", "请从下拉列表中选择XXX");
  validation.CreateErrorBox("输入值有误", "请从下拉列表中选择XXX");
  validation.SuppressDropDownArrow = true;
  validation.ShowErrorBox = true;
  validation.ShowPromptBox = true;
  sheetHead.AddValidationData(validation);
}

#endregion

Excel导出,添加有效性

标签:++   字符   下拉列表   show   eva   rbo   exp   tab   tco   

原文地址:https://www.cnblogs.com/spketoo/p/11684125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!