问题出现原因

HSSFWorkbook对于单元格提供下拉选项的个数限制了255长度问题,这个时候可以使用XSSFWorkbook并把候选项以列显示可以解决了

解决代码

//导出execelpublic void exportComboxExcel(OutputStream fos) {try {workbook = new XSSFWorkbook();//excel文件对象XSSFSheet sheet1 = workbook.createSheet("sheet1");//工作表对象//设置列头样式  this.setTitleCellStyles(workbook, sheet1);//设置数据样式  this.setDataCellStyles(workbook, sheet1);//创建一个隐藏页和隐藏数据集  List<Map<String, Object>> list = createHideSheet();//创建一行列头数据  this.creatAppRowHead(sheet1, 1);//创建一行数据  for (int i = 2; i < 3; i++) {//this.creatAppRow(sheet1, i, i);this.creatAppRow(sheet1, i, i, 0,list);}workbook.write(fos);fos.flush();fos.close();} catch (FileNotFoundException e) {log.error(e.getMessage(), e);} catch (IOException e) {log.error(e.getMessage(), e);}}
 //execel头信息public void creatAppRowHead(XSSFSheet userinfosheet1, int naturalRowIndex) {XSSFRow row = userinfosheet1.createRow(naturalRowIndex - 1);//0.字段名XSSFCell usernameCell = row.createCell(0);usernameCell.setCellValue("字段名");usernameCell.setCellStyle(titleStyle);//1.字段名XSSFCell loginidCell = row.createCell(1);loginidCell.setCellValue("字段名");loginidCell.setCellStyle(titleStyle);//2.字段名 XSSFCell titleTimeCell = row.createCell(2);titleTimeCell.setCellValue("字段名");titleTimeCell.setCellStyle(titleStyle);//3.字段名XSSFCell mobilCell = row.createCell(3);mobilCell.setCellValue("字段名");mobilCell.setCellStyle(titleStyle);//4.字段名XSSFCell emailCell = row.createCell(4);emailCell.setCellValue("字段名");emailCell.setCellStyle(titleStyle);//5.字段名XSSFCell orgCell = row.createCell(5);orgCell.setCellValue("字段名");orgCell.setCellStyle(titleStyle);//6.字段名XSSFCell roleCell = row.createCell(6);roleCell.setCellValue("字段名");roleCell.setCellStyle(titleStyle);//7.字段名XSSFCell areaCell = row.createCell(7);areaCell.setCellValue("字段名");areaCell.setCellStyle(titleStyle);//8.字段名XSSFCell vipCell = row.createCell(8);vipCell.setCellValue("字段名");vipCell.setCellStyle(titleStyle);//9 字段名XSSFCell wxCell = row.createCell(9);wxCell.setCellValue("字段名");wxCell.setCellStyle(titleStyle);//9 字段名XSSFCell qqCell = row.createCell(10);qqCell.setCellValue("字段名");qqCell.setCellStyle(titleStyle);//9 字段名XSSFCell idCardCell = row.createCell(11);idCardCell.setCellValue("字段名");idCardCell.setCellStyle(titleStyle);//10.字段名XSSFCell personTypeCell = row.createCell(12);personTypeCell.setCellValue("字段名");personTypeCell.setCellStyle(titleStyle);}
/*** 创建一列应用数据** @param userinfosheet1* @param userName*/public void creatAppRow(XSSFSheet userinfosheet1, int num, int naturalRowIndex, int cellIndex, List<Map<String, Object>> selectIndexList) {//构造一个信息输入表单,用户姓名,出生省份,出生城市//要求省份是可以下拉选择的,出生城市根据所选择的省份级联下拉选择//在第一行第一个单元格,插入下拉框XSSFRow row = userinfosheet1.createRow(naturalRowIndex - 1);//0.字段名XSSFCell serialNumberCell = row.createCell(0);serialNumberCell.setCellValue("张三");serialNumberCell.setCellStyle(dataStyle);//1.字段名XSSFCell loginidCell = row.createCell(1);loginidCell.setCellValue("zhangs");loginidCell.setCellStyle(dataStyle);//2.字段名XSSFCell titelCell = row.createCell(2);titelCell.setCellValue("zhangs");titelCell.setCellStyle(dataStyle);//3.字段名XSSFCell mobilCell = row.createCell(3);mobilCell.setCellValue("15888888888");mobilCell.setCellStyle(dataStyle);//4.字段名XSSFCell emailCell = row.createCell(4);emailCell.setCellValue("zhangs123@163.com");emailCell.setCellStyle(dataStyle);//5.字段名XSSFCell orgCell = row.createCell(5);orgCell.setCellValue("");orgCell.setCellStyle(dataStyle);//6.字段名XSSFCell roleCell = row.createCell(6);roleCell.setCellValue("");roleCell.setCellStyle(dataStyle);//7.字段名XSSFCell areaCell = row.createCell(7);areaCell.setCellValue("");areaCell.setCellStyle(dataStyle);//7.字段名XSSFCell vipCell = row.createCell(8);vipCell.setCellValue("");vipCell.setCellStyle(dataStyle);//8.字段名XSSFCell weChatCell = row.createCell(9);weChatCell.setCellValue("");weChatCell.setCellStyle(dataStyle);//9.字段名XSSFCell qqNumCell = row.createCell(10);qqNumCell.setCellValue("");qqNumCell.setCellStyle(dataStyle);//10.字段名XSSFCell idCardCell = row.createCell(11);idCardCell.setCellValue("");idCardCell.setCellStyle(dataStyle);//10.字段名XSSFCell personTypeCell = row.createCell(12);personTypeCell.setCellValue("");personTypeCell.setCellStyle(dataStyle);try {if(selectIndexList != null && selectIndexList.size() > 0){//绑定下拉数据for(Map<String,Object> map : selectIndexList){//得到验证对象, 工作表添加验证数据//从1开始下拉框处于第几列);addDataValidation (userinfosheet1, map, naturalRowIndex);}}}catch (Exception e){log.error("绑定数据有误");log.error(e.getMessage(), e);}}

 /****创建隐藏sheet,存储下拉候选值*/public List<Map<String,Object>> createHideSheet(){XSSFSheet orgdataSheet = workbook.createSheet("orgdata");//设置隐藏页标志workbook.setSheetHidden(workbook.getSheetIndex(orgdataSheet), true);List<Map<String, Object>> list = new ArrayList<>();Map<String, Object> map = new HashMap<>();map.put("key", "orgdata");map.put("index", 6);/*!$A$1:$A$127, 这个是excel纵向列的单元格排序规则,根据自身的需要,自行遍历更新拼接*/map.put("record","!$A$1:$A$127");map.put("obj", orgdataSheet);list.add(map);return list;}private String doHandle(final int num) {String[] charArr = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};return charArr[num - 1].toString();}
//把下拉候选项与导出表格中的单元格进行绑定public void addDataValidation(XSSFSheet sheet, Map<String, Object> map, int rowIndex) {String key = MapUtils.getString(map, "key");int naturalRowIndex =  MapUtils.getIntValue(map, "index");String record = MapUtils.getString(map, "record");XSSFSheet hideSheet = (XSSFSheet) MapUtils.getObject(map, "obj");String strFormula = hideSheet.getSheetName()+record;XSSFDataValidationConstraint constraint = new XSSFDataValidationConstraint(DataValidationConstraint.ValidationType.LIST, strFormula);//设置数据有效性加载在哪个单元格上。//四个参数分别是:起始行、终止行、起始列、终止列int firstRow = rowIndex - 1;int lastRow = rowIndex - 1;int firstCol = naturalRowIndex - 1;int lastCol = naturalRowIndex - 1;CellRangeAddressList regions = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol);// 数据有效性对象DataValidationHelper help = new XSSFDataValidationHelper(sheet);DataValidation validation = help.createValidation(constraint, regions);sheet.addValidationData(validation);}

Invalid column index (256). Allowable column range for BIFF8 is (0..255) or (‘A‘..‘IV‘)异常,处理方法记录相关推荐

  1. java.lang.IllegalArgumentException: Invalid column index (256). Allowable column range for BIFF8 is

    今天 用poi 做表格导出的时候 报错了 java.lang.IllegalArgumentException: Invalid column index (256). Allowable colum ...

  2. EasyExcel导出xlsx报错 Invalid column index (256). Allowable column range for BIFF8

    工作中遇到导出xlsx格式的excel文件,有600多列.根据报错提示只能支持256列搜索到的原因及解决方案如下 原因:HSSFWorkbook类只能生成Excel最多256列数据 HSSFWorkb ...

  3. 解决java.lang.IllegalArgumentException: Invalid column index (256). Allowable column range for BIFF8

    在我们使用的jar包 <dependency>             <groupId>org.jeecgframework</groupId>         ...

  4. 成功解决ValueError: column index (256) not an int in range(256)

    成功解决ValueError: column index (256) not an int in range(256) 目录 解决问题 解决思路 解决方法 解决问题 ValueError: colum ...

  5. android 输入模糊匹配_Android 模糊搜索rawquery bind or column index out of range:

    今天使用了android里面的sqlite的模糊查询出错了: android.database.sqlite.SQLiteException: bind or column index out of ...

  6. Spring Boot:Exception parsing document: template=index, line 7 - column 3

    最近这段时间在使用Spring Boot工程中访问静态html页面, 文件目录, -src/main/resources -templates -index.html -static -js -css ...

  7. GGS ERROR 160 Bad column index

    最近由于一个数据库正在升级"改造",部分表结构做了一些调整,以致GoldenGate进程出现了ABENDED状态,下面分享一个因GoldenGate源端表结构发生变化后,引起Gol ...

  8. Debezium报错处理系列十一:Data row is smaller than a column index, internal schema representation is probabl

    Debezium报错处理系列十一:Data row is smaller than a column index, internal schema representation is probably ...

  9. R语言使用多个数据类型不同的向量数据创建一个dataframe数据对象、使用[]操作符和列索引数值访问dataframe指定数据列的数据(column index)

    R语言使用多个数据类型不同的向量数据创建一个dataframe数据对象.使用[]操作符和列索引数值访问dataframe指定数据列的数据(column index) 目录 R语言使用多个数据类型不同的 ...

最新文章

  1. java异常对象引用变量_Java面向对象编程-异常处理
  2. 关于MySQL内核,一定要知道的!
  3. java中创建对象的方式
  4. 给你30秒的时间,你会用Excel制作出一个抽奖功能吗?
  5. C++之指针探究(一):一级指针和二级指针
  6. 【运维技术】数据库主从同步搭建
  7. opencv鼠标回调函数实现ROI区域像素值相同化
  8. 视频教程-【思科CCNA理论专题:9】-- ACL理论-思科认证
  9. 沪江快速手机打字软件下载
  10. 想了解直播系统开发用什么语言?
  11. 《匆匆那年》每一集的标题
  12. find7 android 5,5.5英寸四核芯 OPPO Find 7轻装版评测
  13. #第七章 双波不干涉理论 ​一、双波不干涉理论的分级方法
  14. SEGMENT_VARIABLE什么意思?
  15. Win10 开机默认开启数字小键盘的方法
  16. serializers.serialize
  17. eclipse突然打不开,双击没反应
  18. 笔记:Smith圆图及其计算
  19. 如何从iCloud中下载元气骑士存档
  20. 官僚、傲慢、冷漠的腾讯开放平台

热门文章

  1. P2-21js-ajax
  2. ubuntu:mencoder为我的iriver p7 压带字幕文件的视频
  3. Educoder 分布式文件系统HDFS
  4. WinMount会引起C:\Windows\Explorer.exe崩溃
  5. 51cto MySQL OCP认证精品班5期
  6. 【 Qt编写一个串口助手】
  7. linux 在家工作_在家工作和适当的业务
  8. Anaconda Live 安装器 OS 防呆功能
  9. 惠普战66proG1 BIOS/固件设置Intel VT-x为enable
  10. linux服务器重启分析