Excel导出,添加有效性
#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
推荐阅读