首先描述下问题,问题很奇怪:
下拉菜单设置的所有值的总字符长度超过一定长度(目前我测的是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);