qq_19260033
小付同学哦
2018-02-05 13:03

Java POI设置2013Excel的单元格的下拉菜单的值,出现的问题

10
  • excel
  • java
  • 下拉菜单
  • poi

首先描述下问题,问题很奇怪:
下拉菜单设置的所有值的总字符长度超过一定长度(目前我测的是250个汉字长度),输出Excel正常,代码不报错,但是打开输出的Excel,会出现一下提示_
图片说明
如果250以内,则不会有任何问题~

看一下源码(重点部分):

        Workbook workbook = ExcelIO.getTempletFile("C:\\Users\\99731\\Desktop\\Report\\Template\\t1.xlsx");

        Sheet sheet = workbook.getSheet("t1");

        Row row = sheet.createRow(0);

        Cell cell = row.createCell(0);

        String [] list = {
            "哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔",
            "哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔",
            "哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔",
            "哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔",
            "哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔哇咔咔咔咔",
            "1"
        };

        CellRangeAddressList addressList = new CellRangeAddressList(0,0,0,0);

        DataValidationHelper helper = new XSSFDataValidationHelper((XSSFSheet) sheet);

        XSSFDataValidationConstraint dvConstraint =  (XSSFDataValidationConstraint) helper.createExplicitListConstraint(list);

        DataValidation dataValidation = helper.createValidation(dvConstraint, addressList);

        sheet.addValidationData(dataValidation);

        boolean result = ExcelIO.outputReport(workbook, "test1.xlsx");

        System.out.println(result);
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐