欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Excel导出,添加有效性

程序员文章站 2022-06-07 10:59:10
#region 添加有效性 DataTable dt = LAbll.LogisticsAccounts(DeptId); //查数据 if (dt.Rows.Count < 20) //有效性字符限制255,一组字符12加分割符=13 { string[] strs = {}; for (int ......

#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