生成下拉列表中出现的问题
- 当一个单元格中的字节超过255时,会报异常,
java.lang.IllegalArgumentException: String literals in formulas can’t be bigger than 255 characters ASCII
一般情况下生成下拉列表中使用的方法
String[] textList, int firstRow, int endRow, int firstCol,
int endCol) {
// 加载下拉列表内容
DVConstraint constraint = DVConstraint.createExplicitListConstraint(textList);
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(firstRow,endRow, firstCol, endCol);
// 数据有效性对象
HSSFDataValidation data_validation_list = new HSSFDataValidation(regions, constraint);
realSheet.addValidationData(data_validation_list);
return realSheet;
}
DVConstraint constraint = DVConstraint.createExplicitListConstraint(textList);==直接加载数组textList==
当数组过大则需再创建一个sheet也存放数据,再将sheet引用到真正的realSheet中
- 完整示例
public static void main(String[] args) throws IOException {
String[] countryName = {
"张新花", "赵峰", "刘丹", "黄生功", "李春楠", "马艳珍", "张建群", "赵瑞年", "井含英", "郭元维", "王文芳",
"段国英", "张文婷", "陈鹏英", "常发梅", "孔繁菲", "祁洪香", "韩雅楠", "范明奎", "任顺龙", "丁永乐", "马德录",

在使用POI生成EXCEL下拉列表时,如果单元格字节数超过255,会出现异常。解决方案是当数组过大时,创建额外的隐藏sheet存放数据,然后定义名称并引用到实际工作表中。此方法可以解决字数限制问题。
最低0.47元/天 解锁文章
5827

被折叠的 条评论
为什么被折叠?



