我先创建了隐藏sheet存放原始数据,然后读取到显示sheet作为下拉选项,
问题:导出的excel打开无法显示下拉选项,须先打开隐藏列表才能正常显示。
请问如何解决?(新手,暂时没豆~)
业务代码如下:
//将集合放入原始数据表 HSSFRow row = baseSheet.createRow(0); createRowValues(row, type_names, 0, type_names.size()-1); int index = 1; for(String type_name : type_names){ List<String> fnsn_names = childrenMap.get(type_name); row = baseSheet.createRow(index); createRowValues(row, fnsn_names, 0, fnsn_names.size()-1); index++; } //在名称管理器创建名称 createName(wb, "type", "原始数据!$A$1:$"+getColWord(type_names.size())+"$1");//父集 index = 2; Iterator<Map.Entry<String,List<String>>> it = childrenMap.entrySet().iterator(); System.out.println("第一级下拉选:"+childrenMap.entrySet().size()); while(it.hasNext()){//取出键值 Map.Entry<String,List<String>> entry = (Map.Entry<String,List<String>>)it.next(); System.out.println(entry.getKey()+":"+entry.getValue().size()); System.out.println("行数:"+index); if(entry.getValue().size()>0){//是否还有子集 createName(wb, entry.getKey(), "原始数据!$A$"+index+":$"+getColWord(entry.getValue().size())+"$"+index); } index++; } //将原始数据表隐藏 wb.setSheetHidden(sheetIndex, true); HSSFSheet sheet = wb.createSheet("aaa"); //创建中英文表头 HSSFRow row1 = sheet.createRow(0); HSSFRow row2 = sheet.createRow(1); createRowValues(row1, Arrays.asList(column_chn), 0, 12); createRowValues(row2, Arrays.asList(column_eng), 0, 12); //通过名称设置数据有效性 int rowNum = 1000; HSSFDataValidation validation1 = setDataValidation("type", 2, rowNum-1, 3, 3); sheet.addValidationData(validation1); for(int i=2;i<rowNum;i++){ HSSFDataValidation validation2 = setDataValidation("INDIRECT($D$"+(i+1)+")", i, i, 4, 4); sheet.addValidationData(validation2); } //导出excel String excelPath = "F:\\tts9\\Git\\导出文件\\export data.xls"; FileOutputStream fileOut = new FileOutputStream(excelPath); wb.write(fileOut); fileOut.close();
先创建显示列表再创建隐藏列表,则显示正常