VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • 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


相关教程