zoukankan      html  css  js  c++  java
  • Excel导出下拉框(导出下拉框较多的选项)

    二、导出下拉框较多的选项

    使用常规下拉框的导出,会出现超过255字段异常的问题,可以使用引用隐藏的sheet来解决

    #region 设置下拉框
    if (dicDropList != null)
    {
    int bookIdenx = 1;
    foreach (var item in dicDropList)
    {
    if (item.Value == null || item.Value.Rows.Count == 0)
    {
    continue;
    }
    ISheet sheet2 = workbook.CreateSheet("ShtDictionary" + item.Key);
    for (int j = 0; j < item.Value.Rows.Count; j++)
    {
    sheet2.CreateRow(j).CreateCell(0).SetCellValue(item.Value.Rows[j][0].ToString());
    }
    IName range = workbook.CreateName();
    range.RefersToFormula = "ShtDictionary" + item.Key + "!$A$1:$A$" + item.Value.Rows.Count;    //这里引用位置不用错了 "!$A$1:$A$" + item.Value.Rows.Count
    range.NameName = "dicRange" + item.Key;

    CellRangeAddressList regions = new CellRangeAddressList(2, 65535, item.Key, item.Key);
    DVConstraint constraint = DVConstraint.CreateFormulaListConstraint("dicRange" + item.Key);
    HSSFDataValidation dataValidate = new HSSFDataValidation(regions, constraint);
    dataValidate.CreateErrorBox("输入不合法", "请输入下拉列表中的值。");
    sheet.AddValidationData(dataValidate);
    workbook.SetSheetHidden(bookIdenx, true);
    bookIdenx += 1;
    }
    }
    #endregion

  • 相关阅读:
    杂记-2
    2019CSP-S游记
    csp2020
    特征根法小记
    csp模拟赛低级错误及反思
    备份
    黑科技——树剖两次dfs转一次dfs!
    输出天干地支
    蓝桥0531-输出Y
    蓝桥0615-判断四位数字前后两组是否相等
  • 原文地址:https://www.cnblogs.com/zhusk/p/10524986.html
Copyright © 2011-2022 走看看