poi导出Excel(cell单元格里的一串文字,换行显示,设置字体)
/** * 民主推荐结果导出列表,班子换届 * * @param formBean * @param request * @param response * @param redirectAttributes * @throws IOException * @author KLX * @throws ParseException importExcelMztjjgPoi */ @SuppressWarnings("deprecation") @RequestMapping(value = "importExcelMztjjgPoi") public String importExcelMztjjgPoi(FormBean formBean,String PROCESS_ID, HttpServletRequest request, HttpServletResponse response, String PROCESS_TYPE,String D_NUM_ID,String DW_ID,String nodesFlag,String THTJ_NUM_ID) throws IOException { //防止中文乱码 String HIGHER_AUTHORITY = java.net.URLDecoder.decode(request.getParameter("HIGHER_AUTHORITY"), "utf-8"); //谈话人员范围 String TALKRANGE ="xx"; //定义导出模板的标题 String title1 = "民主推荐票汇总(一轮)"; String title2 = "民主推荐票汇总(二轮)"; String TIME=""; Date date = new Date(); //取得当前日期xxxx年xx月xx日格式 SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日"); TIME = format.format(date.getTime()); //投票轮数标识 String twoVoteFlag = "1"; Map<String, Object> idMap1 = Maps.newHashMap(); idMap1.put("NUM_ID", D_NUM_ID); idMap1.put("oneRound", "oneRound"); Map<String, Object> idMap2 = Maps.newHashMap(); idMap2.put("NUM_ID", D_NUM_ID); idMap2.put("secondRound", "secondRound"); List<Map<String, Object>> idList1 = democracyRecommendService.getMztjHytjId(idMap1); List<Map<String, Object>> idList2 = democracyRecommendService.getMztjHytjId(idMap2); String hytjId1 =""; String hytjId2 =""; if(idList1 != null && idList1.size()>0){ hytjId1 = idList1.get(0).get("NUM_ID").toString(); } if(idList2 != null && idList2.size()>0){ hytjId2 = idList2.get(0).get("NUM_ID").toString(); } Map<String, Object> zghMap = Maps.newHashMap(); zghMap.put("PROCESS_ID", PROCESS_ID); //1轮会议提推荐 Map<String, Object> hytjMap1 = Maps.newHashMap(); Map<String, Object> hytj1= null; if(StringUtils.isNotEmpty(hytjId1)){ hytjMap1.put("NUM_ID", hytjId1); hytj1= democracyRecommendService.getMztjHytjInfo(hytjMap1); } //2轮会议推荐 Map<String, Object> hytjMap2 = Maps.newHashMap(); Map<String, Object> hytj2 = null; if(StringUtils.isNotEmpty(hytjId2)){ hytjMap2.put("NUM_ID", hytjId2); hytj2 = democracyRecommendService.getMztjHytjInfo(hytjMap2); } //会议推荐1轮总人数 String SHOULD_NUM1 = "0"; //会议推荐2轮总人数 String SHOULD_NUM2 = "0"; //谈话推荐总人数 String SHOULD_NUM3 = "0"; Map<String, Object> thtj = null; Map<String, Object> hytjMap3 = Maps.newHashMap(); if(StringUtils.isNotEmpty(PROCESS_ID)){ hytjMap3.put("NUM_ID", PROCESS_ID); thtj = democracyRecommendService.getTHTJInfo(hytjMap3); } //取得1轮投票会议投票的人数 if(hytj1 != null && hytj1.size()>0 ){ if(hytj1.containsKey("SHOULD_NUM") && null != hytj1.get("SHOULD_NUM")&& !("").equals(hytj1.get("SHOULD_NUM"))){ SHOULD_NUM1 = hytj1.get("SHOULD_NUM").toString(); } } //取得2轮投票会议投票的人数 if(hytj2 != null && hytj2.size() >0){ if(hytj2.containsKey("SHOULD_NUM") && null != hytj2.get("SHOULD_NUM")&& !("").equals(hytj2.get("SHOULD_NUM"))){ SHOULD_NUM2 = hytj2.get("SHOULD_NUM").toString(); } } //取得2轮投票会议投票的人数 if(thtj != null && thtj.size() >0){ if(thtj.containsKey("ACTUAL_NUM") && null != thtj.get("ACTUAL_NUM")&& !("").equals(thtj.get("ACTUAL_NUM"))){ SHOULD_NUM3 = thtj.get("ACTUAL_NUM").toString(); } if("1".equals(thtj.get("THTJ_RANGE").toString())){ TALKRANGE = "全体教职工"; } else if("2".equals(thtj.get("THTJ_RANGE").toString())){ TALKRANGE = "党政领导班子成员、两委委员、系所中心主任、工会主席、教师党支部书记、各类人才代表、教师(医教研人员)及党政管理人员代表等"; } else if("3".equals(thtj.get("THTJ_RANGE").toString())){ TALKRANGE = "党政领导班子成员、中层干部、副高及以上人员等"; } } //判断进行了几轮投票 if(null != nodesFlag){ if( 6 > Integer.parseint(nodesFlag) && 0!=Integer.parseint(nodesFlag)){ twoVoteFlag ="1"; } else if( 6 <= Integer.parseint(nodesFlag)){ twoVoteFlag ="2"; } else if( 0 == Integer.parseint(nodesFlag)){ twoVoteFlag ="2"; } else{ twoVoteFlag ="1"; } } // 职务集合 Map<String, Object> postMap = Maps.newHashMap(); postMap.put("PROCESS_ID", PROCESS_ID); //会议推荐和谈话推荐合并单元格的数量 int titleMergeCell = 0; List<Map<String, Object>> electivePostList = democracyRecommendService .getelectivePostListByProcessId(postMap); OutputStream fos = response.getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(fos); ZipOutputStream zos = new ZipOutputStream(bos); //创建HSSFWorkbook对象(excel的文档对象) HSSFWorkbook wb = new HSSFWorkbook(); HSSFWorkbook wb1 = new HSSFWorkbook(); Map<String, Object> zghMap2 = Maps.newHashMap(); zghMap2.put("PROCESS_ID", PROCESS_ID); //取得你任人集合,确认拟任人 List<Map<String, Object>> quasiPersonList = democracyRecommendService.getQuasiPersonList(zghMap2,null); String[] idArray = {}; if(quasiPersonList!=null){ idArray = new String[quasiPersonList.size()]; for (int i = 0; i < quasiPersonList.size(); i++) { idArray[i] = (String) quasiPersonList.get(i).get("ZGH"); } } //取得党政班子成员 Map<String, Object> dzbzMap = Maps.newHashMap(); dzbzMap.put("DW_ID", DW_ID); List<Map<String, Object>> dzbzList = democracyRecommendService.getDZBZList(dzbzMap); //1轮班子换届的导出结果集 if(Integer.parseint(twoVoteFlag)>= 1){ Map<String, Object> mztjmap1 = Maps.newHashMap(); mztjmap1.put("THTJ_ID", THTJ_NUM_ID); mztjmap1.put("HYTJ_ID", hytjId1); mztjmap1.put("idArray", idArray); //取得1轮民主土建结果 List<Map<String, Object>> mztjJGBZHJlist =democracyRecommendService.getMZTJJGBZHJlist(mztjmap1); //民主推荐总票数 List<Map<String, Object>> MZTJJGBZHJSUM =democracyRecommendService.getMZTJJGBZHJSUM(mztjmap1); List<Map<String, Object>> newList = new ArrayList<Map<String,Object>>(); Boolean addFlag = true; //循环赋值 if(mztjJGBZHJlist!= null && mztjJGBZHJlist.size()>0){ for (int i = 0;i<mztjJGBZHJlist.size();i++){ Map<String, Object> listMap = Maps.newHashMap(); for (int y = 0;y<mztjJGBZHJlist.size();y++){ if(newList.size() >0 ){ for (Map<String, Object> newObjMap:newList){ addFlag = true; if(newObjMap.get("QUASI_ID").toString().equals(mztjJGBZHJlist.get(i).get("QUASI_ID").toString())){ addFlag = false; break ; } } } if( addFlag && mztjJGBZHJlist.get(i).get("QUASI_ID").equals(mztjJGBZHJlist.get(y).get("QUASI_ID"))){ listMap.put("QUASI_ID", mztjJGBZHJlist.get(i).get("QUASI_ID")); listMap.put("XM", mztjJGBZHJlist.get(i).get("XM")); if(mztjJGBZHJlist.get(y).containsKey("POST_ID") && null !=mztjJGBZHJlist.get(y).get("POST_ID")){ listMap.put("POST_ID"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"), mztjJGBZHJlist.get(y).get("POST_ID")); } //得票数 if(mztjJGBZHJlist.get(y).containsKey("M_GET_NUM") && null !=mztjJGBZHJlist.get(y).get("M_GET_NUM")){ listMap.put("M_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"), mztjJGBZHJlist.get(y).get("M_GET_NUM")); } else{ listMap.put("M_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"),"0"); } //有效票数 if(mztjJGBZHJlist.get(y).containsKey("T_GET_NUM") && null !=mztjJGBZHJlist.get(y).get("T_GET_NUM")){ listMap.put("T_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"), mztjJGBZHJlist.get(y).get("T_GET_NUM")); } else{ listMap.put("T_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"),"0"); } } } //将相同的人的不同的职务不同会议或谈话的数据合为一行 if(addFlag){ newList.add(listMap); } } } String str1 = "中山大学"+HIGHER_AUTHORITY+"行政领导班子换届民主推荐情况"+"n"+"(适用于行政班子换届,如开展摸底谈话请添加一栏,填写完敬请排版并调整为可直接打印版式)"; String str11 = "中山大学"+HIGHER_AUTHORITY+"行政领导班子换届民主推荐情况"+"n"; //建立新的sheet对象(excel的表单) HSSFSheet sheet=wb.createSheet(title1); //在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个 HSSFRow row1=sheet.createRow(0); //创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个 HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setWrapText(true); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); HSSFCellStyle cellStyleDZ = wb.createCellStyle(); cellStyleDZ.setWrapText(true); // HSSFWorkbook workbook1 = new HSSFWorkbook(); HSSFFont fontDZ = wb.createFont(); fontDZ.setFontHeightInPoints((short) 14); cellStyleDZ.setFont(fontDZ); cellStyleDZ.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 HSSFCellStyle cellStyleDZHT = wb.createCellStyle(); // 人选姓名 cellStyleDZHT.setWrapText(true); HSSFFont fontDZHT = wb.createFont(); fontDZHT.setFontHeightInPoints((short) 14); // fontDZHT.setFontName("黑体"); fontDZHT.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 宽度 cellStyleDZHT.setFont(fontDZHT); cellStyleDZHT.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 HSSFCellStyle cellStyleDZHT1 = wb.createCellStyle(); // 推荐人选姓名 cellStyleDZHT.setWrapText(true); HSSFFont fontDZHT1 = wb.createFont(); fontDZHT1.setFontHeightInPoints((short) 14); cellStyleDZHT1.setFont(fontDZHT1); cellStyleDZHT1.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 HSSFCellStyle cellStyle1 = wb.createCellStyle(); cellStyle1.setWrapText(true); cellStyle1.setWrapText(true); HSSFFont fontQJZG1 = wb.createFont(); fontQJZG1.setFontName("楷体"); fontQJZG1.setFontHeightInPoints((short) 12); cellStyle1.setFont(fontQJZG1); //设置居中: cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 cellStyle1.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 居中 HSSFCell cell=row1.createCell(0); //TODO cell.setCellStyle(cellStyle); //设置单元格高度 row1.setHeight((short)800); if(null != electivePostList && electivePostList.size() >0){ titleMergeCell = electivePostList.size(); // HSSFWorkbook workbook = new HSSFWorkbook(); HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 14); // 字体高度 font.setFontName("宋体"); // 字体 // font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 宽度 HSSFFont font1 = wb.createFont(); font1.setFontHeightInPoints((short) 9); // 字体高度 font1.setFontName("宋体"); // 字体 // font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 宽度 //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 CellRangeAddress region = new CellRangeAddress(0,0,0,titleMergeCell+titleMergeCell+titleMergeCell); //给定要合并的单元格范围 sheet.addMergedRegion(region); setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb); HSSFRichTextString ts= new HSSFRichTextString(str1); ts.applyFont(0,str11.length(),font); ts.applyFont(str11.length(),ts.length(),font1); cell.setCellValue(ts); sheet.setDefaultColumnWidth(20); sheet.setDefaultRowHeightInPoints(20); //在sheet里创建第二行 HSSFRow row2=sheet.createRow(1); row2.setHeight((short)500); HSSFCell cell1=row2.createCell(0); HSSFCell cell2= row2.createCell(1); HSSFCell cell3=row2.createCell((1+titleMergeCell)); HSSFCell cell4=row2.createCell((1+titleMergeCell+titleMergeCell)); cell1.setCellStyle(cellStyle); cell2.setCellStyle(cellStyle); cell3.setCellStyle(cellStyle); cell4.setCellStyle(cellStyle); //上或者下从0开始会议推荐 CellRangeAddress region1 = new CellRangeAddress(1,1,1,(short) (titleMergeCell)); //给定要合并的单元格范围 // sheet.addMergedRegion(new Region(1, (short) 1, 1, (short) (titleMergeCell))); sheet.addMergedRegion(region1); setBorderStyle(HSSFCellStyle.BORDER_THIN, region1, sheet, wb); //上或者下从0开始谈话推荐 CellRangeAddress region2 = new CellRangeAddress(1,1,(short)(1+titleMergeCell),(short) (titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region2); setBorderStyle(HSSFCellStyle.BORDER_THIN, region2, sheet, wb); // sheet.addMergedRegion(new Region(1, (short) (1+titleMergeCell), 1, (short) (titleMergeCell+titleMergeCell))); //上或者下从0开始合计票 CellRangeAddress region3 = new CellRangeAddress(1,1,(short) (1+titleMergeCell+titleMergeCell),(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region3); setBorderStyle(HSSFCellStyle.BORDER_THIN, region3, sheet, wb); // sheet.addMergedRegion(new Region(1, (short) (1+titleMergeCell+titleMergeCell), 1, (short) (titleMergeCell+titleMergeCell+titleMergeCell))); //创建单元格并设置单元格内容 HSSFCell cellrx = row2.createCell(0); cellrx.setCellValue("人选姓名"); cellrx.setCellStyle(cellStyleDZHT1); HSSFCell cellTJ = row2.createCell(1); cellTJ.setCellValue("会议推荐("+SHOULD_NUM1+"人)"); cellTJ.setCellStyle(cellStyleDZHT1); HSSFCell cellTJTJ = row2.createCell((1+titleMergeCell)); cellTJTJ.setCellValue("谈话推荐("+SHOULD_NUM3+"人)"); cellTJTJ.setCellStyle(cellStyleDZHT1); HSSFCell cellHJP = row2.createCell((1+titleMergeCell+titleMergeCell)); cellHJP.setCellValue("合计票"); cellHJP.setCellStyle(cellStyleDZHT1); HSSFRow row3=sheet.createRow(2); row3.setHeight((short)500); List<Map<String, Object>> postList = new ArrayList<Map<String,Object>>(); postList.addAll(electivePostList); postList.addAll(electivePostList); postList.addAll(electivePostList); //职务标题 for(int y=0;y<titleMergeCell+titleMergeCell+titleMergeCell;y++){ HSSFCell cellrow3 = row3.createCell(y+1); cellrow3.setCellStyle(cellStyle); cellrow3.setCellValue(postList.get(y).get("EP_POST_NAME").toString()); } //用于现党政班子成员推荐情况表格打印的索引 int rowIndex = 2; //循环赋值 if(newList.size() > 0 ){ for(int i= 0;i<newList.size();i++){ HSSFRow row5=sheet.createRow(3+i); //设置单元格高度 row5.setHeight((short)500); HSSFCell cellrow05 = row5.createCell(0); cellrow05.setCellStyle(cellStyle); cellrow05.setCellValue(newList.get(i).get("XM").toString()); for(int y=0;y<titleMergeCell+titleMergeCell+titleMergeCell;y++){ if(y<=y && y<titleMergeCell){ for(int a =0;a<electivePostList.size();a++){ if(newList.get(i).containsKey("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(y).get("EP_NUM_ID").toString()) && (newList.get(i).get("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(y).get("EP_NUM_ID").toString())).equals(electivePostList.get(y).get("EP_NUM_ID").toString())){ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(newList.get(i).get("M_GET_NUM"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(y).get("EP_NUM_ID").toString()).toString()); }else{ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue("0"); } } } if(titleMergeCell<=y && y<(titleMergeCell+titleMergeCell)){ int num = titleMergeCell+titleMergeCell - y; int index = 0; if(0!=num){ if(0!=(num% titleMergeCell)){ index = titleMergeCell - num% titleMergeCell; } } for(int a =0;a<electivePostList.size();a++){ if(newList.get(i).containsKey("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(index).get("EP_NUM_ID").toString()) && (newList.get(i).get("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(index).get("EP_NUM_ID").toString())).equals(electivePostList.get(index).get("EP_NUM_ID").toString())){ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(newList.get(i).get("T_GET_NUM"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(index).get("EP_NUM_ID").toString()).toString()); }else{ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue("0"); } } } if((titleMergeCell+titleMergeCell) <=y && y<(titleMergeCell+titleMergeCell+titleMergeCell)){ int num = titleMergeCell+titleMergeCell+titleMergeCell - y; int index = 0; if(0!=num){ if(0!=(num% titleMergeCell)){ index =titleMergeCell - num% titleMergeCell; } } String postid = electivePostList.get(index).get("EP_NUM_ID").toString(); if(MZTJJGBZHJSUM != null && MZTJJGBZHJSUM.size()>0){ String val = "0"; for(Map<String, Object> p:MZTJJGBZHJSUM){ if(postid.equals(p.get("POST_ID"))){ if(p.containsKey("heji")){ val = p.get("heji").toString(); } }else{ } } String stcount1 = "0"; String stcount2 = "0"; if(row5.getCell(1+index)!=null){ row5.getCell(1+index).setCellType(Cell.CELL_TYPE_STRING); stcount1 = row5.getCell(1+index).getStringCellValue().replace(" ", ""); } if(row5.getCell(1+titleMergeCell+index)!=null){ row5.getCell(1+titleMergeCell+index).setCellType(Cell.CELL_TYPE_STRING); stcount2 = row5.getCell(1+titleMergeCell+index).getStringCellValue().replace(" ", ""); } int count1 = Integer.parseInt(stcount1); int count2 = Integer.parseInt(stcount2); HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(count1+count2); }else{ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue("0"); } } } rowIndex = 3+i; } } //打印一行空格 HSSFRow row6=sheet.createRow(rowIndex+1); row6.setHeight((short)500); if(titleMergeCell != 0){ for(int t=0;t<titleMergeCell+titleMergeCell+titleMergeCell;t++){ row6.createCell(t); } } //打印现党政班子成员推荐情况 HSSFRow row7=sheet.createRow(rowIndex+2); row7.setHeight((short)500); //循环打印现党政班子成员推荐情况 //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 CellRangeAddress region4 = new CellRangeAddress(rowIndex+2,rowIndex+2,0,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region4); // setBorderStyle(HSSFCellStyle.BORDER_THIN, region4, sheet, wb); // sheet.addMergedRegion(new Region(rowIndex+2, (short) 0, rowIndex+2, (short) (titleMergeCell+titleMergeCell+titleMergeCell))); HSSFCell cell01=row7.createCell(0); cell01.setCellValue("现党政班子成员推荐情况"); cell01.setCellStyle(cellStyleDZ); ////打印现党政班子成员推荐情况标题 HSSFRow row8=sheet.createRow(rowIndex+3); row8.setHeight((short)500); HSSFCell cell11=row8.createCell(0); HSSFCell cell12= row8.createCell(1); HSSFCell cell13=row8.createCell(2); cell11.setCellStyle(cellStyleDZHT); cell12.setCellStyle(cellStyleDZHT); cell13.setCellStyle(cellStyleDZHT); //创建单元格并设置单元格内容 cell11.setCellValue("姓名"); cell12.setCellValue("现职务"); cell13.setCellValue("推荐人选姓名"); //上或者下从0开始合计票 CellRangeAddress region5 = new CellRangeAddress(rowIndex+3,rowIndex+3,2,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region5); setBorderStyle(HSSFCellStyle.BORDER_THIN, region5, sheet, wb); // sheet.addMergedRegion(new Region((rowIndex+3), (short) 2, (rowIndex+3), (short) (titleMergeCell+titleMergeCell+titleMergeCell))); int markIndex = rowIndex+3; if(null != dzbzList && dzbzList.size() >0 ){ //循环遍历姓名,现职务,拟任职务 for(int y=0;y<dzbzList.size();y++){ HSSFRow row9=sheet.createRow(rowIndex+3+y+1); row9.setHeight((short)500); HSSFCell cellrow5 = row9.createCell(0); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(MapUtils.getString(dzbzList.get(y), "XM","")); HSSFCell cellrow51 = row9.createCell(1); cellrow51.setCellStyle(cellStyle); cellrow51.setCellValue(MapUtils.getString(dzbzList.get(y), "DUTIES","")); for(int i=0;i<titleMergeCell+titleMergeCell+titleMergeCell-1;i++){ row9.createCell(i+2).setCellStyle(cellStyle); } CellRangeAddress region51 = new CellRangeAddress((rowIndex+3+y+1),(rowIndex+3+y+1),2,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region51); markIndex = rowIndex+3+y+1; } }else{ //循环遍历姓名,现职务,拟任职务 for(int y=0;y<1;y++){ HSSFRow row9=sheet.createRow(rowIndex+3+y+1); row9.setHeight((short)500); row9.createCell(0).setCellStyle(cellStyle); row9.createCell(1).setCellStyle(cellStyle); for(int i=0;i<titleMergeCell+titleMergeCell+titleMergeCell-1;i++){ row9.createCell(i+2).setCellStyle(cellStyle); } CellRangeAddress region51 = new CellRangeAddress((rowIndex+3+y+1),(rowIndex+3+y+1),2,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region51); markIndex = rowIndex+3+y+1; } } String mark = "注:"+TALKRANGE; mark=mark+ "(此处根据实际填写),应到XX人,实到XX人;发出XX张票,收回XX票,全部有效。"; mark=mark+"n"+"统计人:"; mark=mark+"n"+"复核人:"; mark=mark+"n"+"工作组: "; mark=mark+"n"+"工作组组长(签字): "; mark=mark+"n"+TIME; //打印备注 HSSFRow row10=sheet.createRow(markIndex+1); //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 sheet.addMergedRegion(new Region(markIndex+1, (short) 0, markIndex+1, (short) (titleMergeCell+titleMergeCell+titleMergeCell))); HSSFCell cell02=row10.createCell(0); cell02.setCellValue(mark); cell02.setCellStyle(cellStyle1); //设置单元格高度 row10.setHeight((short)2500); } } //2轮班子换届的导出结果集 if(Integer.parseInt(twoVoteFlag)>= 2){ Map<String, Object> mztjmap1 = Maps.newHashMap(); mztjmap1.put("THTJ_ID", THTJ_NUM_ID); mztjmap1.put("HYTJ_ID", hytjId2); mztjmap1.put("idArray", idArray); //取得1轮民主土建结果 List<Map<String, Object>> mztjJGBZHJlist =democracyRecommendService.getMZTJJGBZHJlist(mztjmap1); //民主推荐总票数 List<Map<String, Object>> MZTJJGBZHJSUM =democracyRecommendService.getMZTJJGBZHJSUM(mztjmap1); List<Map<String, Object>> newList = new ArrayList<Map<String,Object>>(); boolean addFlag = true; //循环赋值 if(mztjJGBZHJlist!= null && mztjJGBZHJlist.size()>0){ for(int i = 0;i<mztjJGBZHJlist.size();i++){ Map<String, Object> listMap = Maps.newHashMap(); for(int y = 0;y<mztjJGBZHJlist.size();y++){ if(newList.size() >0 ){ for(Map<String, Object> newObjMap:newList){ addFlag = true; if(newObjMap.get("QUASI_ID").toString().equals(mztjJGBZHJlist.get(i).get("QUASI_ID").toString())){ addFlag = false; break ; } } } if( addFlag && mztjJGBZHJlist.get(i).get("QUASI_ID").equals(mztjJGBZHJlist.get(y).get("QUASI_ID"))){ listMap.put("QUASI_ID", mztjJGBZHJlist.get(i).get("QUASI_ID")); listMap.put("XM", mztjJGBZHJlist.get(i).get("XM")); if(mztjJGBZHJlist.get(y).containsKey("POST_ID") && null !=mztjJGBZHJlist.get(y).get("POST_ID")){ listMap.put("POST_ID"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"), mztjJGBZHJlist.get(y).get("POST_ID")); } //得票数 if(mztjJGBZHJlist.get(y).containsKey("M_GET_NUM") && null !=mztjJGBZHJlist.get(y).get("M_GET_NUM")){ listMap.put("M_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"), mztjJGBZHJlist.get(y).get("M_GET_NUM")); }else{ listMap.put("M_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"),"0"); } //有效票数 if(mztjJGBZHJlist.get(y).containsKey("T_GET_NUM") && null !=mztjJGBZHJlist.get(y).get("T_GET_NUM")){ listMap.put("T_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"), mztjJGBZHJlist.get(y).get("T_GET_NUM")); }else{ listMap.put("T_GET_NUM"+mztjJGBZHJlist.get(y).get("QUASI_ID")+mztjJGBZHJlist.get(y).get("POST_ID"),"0"); } } } //将相同的人的不同的职务不同会议或谈话的数据合为一行 if(addFlag){ newList.add(listMap); } } } //建立新的sheet对象(excel的表单) HSSFSheet sheet=wb1.createSheet(title2); //在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个 HSSFRow row1=sheet.createRow(0); //创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个 HSSFCellStyle cellStyle = wb1.createCellStyle(); cellStyle.setWrapText(true); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); HSSFCellStyle cellStyleDZ = wb1.createCellStyle(); cellStyleDZ.setWrapText(true); HSSFFont fontDZ = wb1.createFont(); fontDZ.setFontHeightInPoints((short) 14); cellStyleDZ.setFont(fontDZ); cellStyleDZ.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 HSSFCellStyle cellStyleDZHT = wb1.createCellStyle(); cellStyleDZHT.setWrapText(true); HSSFFont fontDZHT = wb1.createFont(); fontDZHT.setFontHeightInPoints((short) 14); fontDZHT.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 宽度 cellStyleDZHT.setFont(fontDZHT); cellStyleDZHT.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyleDZHT.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 HSSFCellStyle cellStyleDZHT1 = wb1.createCellStyle(); cellStyleDZHT.setWrapText(true); HSSFFont fontDZHT1 = wb1.createFont(); fontDZHT1.setFontHeightInPoints((short) 14); cellStyleDZHT1.setFont(fontDZHT1); cellStyleDZHT1.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyleDZHT1.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 HSSFCellStyle cellStyle1 = wb1.createCellStyle(); cellStyle1.setWrapText(true); cellStyle1.setWrapText(true); HSSFFont fontQJZG1 = wb1.createFont(); fontQJZG1.setFontHeightInPoints((short) 12); cellStyle1.setFont(fontQJZG1); //设置居中: cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 cellStyle1.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 居中 //设置居中: cellStyle1.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 居中 HSSFCell cell=row1.createCell(0); cell.setCellStyle(cellStyle); //设置单元格高度 row1.setHeight((short)800); if(null != electivePostList && electivePostList.size() >0){ titleMergeCell = electivePostList.size(); HSSFFont font = wb1.createFont(); font.setFontHeightInPoints((short) 14); // 字体高度 font.setFontName("宋体"); // 字体 HSSFFont font1 = wb1.createFont(); font1.setFontHeightInPoints((short) 9); // 字体高度 font1.setFontName("宋体"); // 字体 String str2 = "中山大学"+HIGHER_AUTHORITY+"行政领导班子换届民主推荐情况"+"n"+"(适用于行政班子换届,如开展摸底谈话请添加一栏,填写完敬请排版并调整为可直接打印版式)"; String str22 = "中山大学"+HIGHER_AUTHORITY+"行政领导班子换届民主推荐情况"+"n"; // cell.setCellStyle(cellStyle); //设置单元格内容 // cell.setCellValue(str2); //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 CellRangeAddress region = new CellRangeAddress(0,0,0,titleMergeCell+titleMergeCell+titleMergeCell); //给定要合并的单元格范围 sheet.addMergedRegion(region); setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb1); HSSFRichTextString ts= new HSSFRichTextString(str22); ts.applyFont(0,str22.length(),font); ts.applyFont(str22.length(),ts.length(),font1); cell.setCellValue(ts); sheet.setDefaultColumnWidth(20);// 设置列宽 sheet.setDefaultRowHeightInPoints(20); //在sheet里创建第二行 HSSFRow row2=sheet.createRow(1); row2.setHeight((short)500); HSSFCell cell1=row2.createCell(0); HSSFCell cell2= row2.createCell(1); HSSFCell cell3=row2.createCell((1+titleMergeCell)); HSSFCell cell4=row2.createCell((1+titleMergeCell+titleMergeCell)); cell1.setCellStyle(cellStyle); cell2.setCellStyle(cellStyle); cell3.setCellStyle(cellStyle); cell4.setCellStyle(cellStyle); //上或者下从0开始会议推荐 CellRangeAddress region1 = new CellRangeAddress(1,1,1,(short) (titleMergeCell)); //给定要合并的单元格范围 // sheet.addMergedRegion(new Region(1, (short) 1, 1, (short) (titleMergeCell))); sheet.addMergedRegion(region1); setBorderStyle(HSSFCellStyle.BORDER_THIN, region1, sheet, wb1); //上或者下从0开始谈话推荐 CellRangeAddress region2 = new CellRangeAddress(1,1,(short)(1+titleMergeCell),(short) (titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region2); setBorderStyle(HSSFCellStyle.BORDER_THIN, region2, sheet, wb1); // sheet.addMergedRegion(new Region(1, (short) (1+titleMergeCell), 1, (short) (titleMergeCell+titleMergeCell))); //上或者下从0开始合计票 CellRangeAddress region3 = new CellRangeAddress(1,1,(short) (1+titleMergeCell+titleMergeCell),(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region3); setBorderStyle(HSSFCellStyle.BORDER_THIN, region3, sheet, wb1); //创建单元格并设置单元格内容 //创建单元格并设置单元格内容 HSSFCell cellrx = row2.createCell(0); cellrx.setCellValue("人选姓名"); cellrx.setCellStyle(cellStyleDZHT1); HSSFCell cellTJ = row2.createCell(1); cellTJ.setCellValue("会议推荐("+SHOULD_NUM1+"人)"); cellTJ.setCellStyle(cellStyleDZHT1); HSSFCell cellTJTJ = row2.createCell((1+titleMergeCell)); cellTJTJ.setCellValue("谈话推荐("+SHOULD_NUM3+"人)"); cellTJTJ.setCellStyle(cellStyleDZHT1); HSSFCell cellHJP = row2.createCell((1+titleMergeCell+titleMergeCell)); cellHJP.setCellValue("合计票"); cellHJP.setCellStyle(cellStyleDZHT1); HSSFRow row3=sheet.createRow(2); row3.setHeight((short)500); List<Map<String, Object>> postList = new ArrayList<Map<String,Object>>(); postList.addAll(electivePostList); postList.addAll(electivePostList); postList.addAll(electivePostList); //职务标题 for(int y=0;y<titleMergeCell+titleMergeCell+titleMergeCell;y++){ HSSFCell cellrow3 = row3.createCell(y+1); cellrow3.setCellStyle(cellStyle); cellrow3.setCellValue(postList.get(y).get("EP_POST_NAME").toString()); } int rowIndex = 3; //循环赋值 if(newList.size() > 0 ){ for(int i= 0;i<newList.size();i++){ HSSFRow row5=sheet.createRow(3+i); row5.setHeight((short)500); HSSFCell cellrow05 = row5.createCell(0); cellrow05.setCellStyle(cellStyle); cellrow05.setCellValue(newList.get(i).get("XM").toString()); for(int y=0;y<titleMergeCell+titleMergeCell+titleMergeCell;y++){ if(y<=y && y<titleMergeCell){ for(int a =0;a<electivePostList.size();a++){ if(newList.get(i).containsKey("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(y).get("EP_NUM_ID").toString()) && (newList.get(i).get("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(y).get("EP_NUM_ID").toString())).equals(electivePostList.get(y).get("EP_NUM_ID").toString())){ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(newList.get(i).get("M_GET_NUM"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(y).get("EP_NUM_ID").toString()).toString()); }else{ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue("0"); } } } if(titleMergeCell<=y && y<(titleMergeCell+titleMergeCell)){ int num = titleMergeCell+titleMergeCell - y; int index = 0; if(0!=num){ if(0!=(num% titleMergeCell)){ index = titleMergeCell - num% titleMergeCell; } } for(int a =0;a<electivePostList.size();a++){ if(newList.get(i).containsKey("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(index).get("EP_NUM_ID").toString()) && (newList.get(i).get("POST_ID"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(index).get("EP_NUM_ID").toString())).equals(electivePostList.get(index).get("EP_NUM_ID").toString())){ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(newList.get(i).get("T_GET_NUM"+newList.get(i).get("QUASI_ID").toString()+electivePostList.get(index).get("EP_NUM_ID").toString()).toString()); }else{ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue("0"); } } } if((titleMergeCell+titleMergeCell) <=y && y<(titleMergeCell+titleMergeCell+titleMergeCell)){ int num = titleMergeCell+titleMergeCell+titleMergeCell - y; int index = 0; if(0!=num){ if(0!=(num% titleMergeCell)){ index =titleMergeCell - num% titleMergeCell; } } String postid = electivePostList.get(index).get("EP_NUM_ID").toString(); if(MZTJJGBZHJSUM != null && MZTJJGBZHJSUM.size()>0){ String val = "0"; for(Map<String, Object> p:MZTJJGBZHJSUM){ if(postid.equals(p.get("POST_ID"))){ if(p.containsKey("heji")){ val = p.get("heji").toString(); } }else{ } } String stcount1 = "0"; String stcount2 = "0"; if(row5.getCell(1+index)!=null){ row5.getCell(1+index).setCellType(Cell.CELL_TYPE_STRING); stcount1 = row5.getCell(1+index).getStringCellValue().replace(" ", ""); } if(row5.getCell(1+titleMergeCell+index)!=null){ row5.getCell(1+titleMergeCell+index).setCellType(Cell.CELL_TYPE_STRING); stcount2 = row5.getCell(1+titleMergeCell+index).getStringCellValue().replace(" ", ""); } int count1 = Integer.parseInt(stcount1); int count2 = Integer.parseInt(stcount2); HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(count1+count2); }else{ HSSFCell cellrow5 = row5.createCell(y+1); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue("0"); } } } rowIndex = 3+i; } } //循环打印现党政班子成员推荐情况 //打印一行空格 HSSFRow row6=sheet.createRow(rowIndex+1); row6.setHeight((short)500); if(titleMergeCell != 0){ for(int t=0;t<titleMergeCell+titleMergeCell+titleMergeCell;t++){ row6.createCell(t); } } //打印现党政班子成员推荐情况 HSSFRow row7=sheet.createRow(rowIndex+2); row7.setHeight((short)500); //循环打印现党政班子成员推荐情况 //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 CellRangeAddress region4 = new CellRangeAddress(rowIndex+2,rowIndex+2,0,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region4); HSSFCell cell01=row7.createCell(0); cell01.setCellValue("现党政班子成员推荐情况"); cell01.setCellStyle(cellStyleDZ); ////打印现党政班子成员推荐情况标题 HSSFRow row8=sheet.createRow(rowIndex+3); row8.setHeight((short)500); HSSFCell cell11=row8.createCell(0); HSSFCell cell12= row8.createCell(1); HSSFCell cell13=row8.createCell(2); cell11.setCellStyle(cellStyleDZHT); cell12.setCellStyle(cellStyleDZHT); cell13.setCellStyle(cellStyleDZHT); //创建单元格并设置单元格内容 cell11.setCellValue("姓名"); cell12.setCellValue("现职务"); cell13.setCellValue("推荐人选姓名"); //上或者下从0开始合计票 CellRangeAddress region5 = new CellRangeAddress(rowIndex+3,rowIndex+3,2,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region5); setBorderStyle(HSSFCellStyle.BORDER_THIN, region5, sheet, wb1); int markIndex = rowIndex+3; //循环遍历姓名,现职务,拟任职务 if(null != dzbzList && dzbzList.size() >0 ){ //循环遍历姓名,现职务,拟任职务 for(int y=0;y<dzbzList.size();y++){ HSSFRow row9=sheet.createRow(rowIndex+3+y+1); row9.setHeight((short)500); HSSFCell cellrow5 = row9.createCell(0); cellrow5.setCellStyle(cellStyle); cellrow5.setCellValue(MapUtils.getString(dzbzList.get(y), "XM","")); HSSFCell cellrow51 = row9.createCell(1); cellrow51.setCellStyle(cellStyle); cellrow51.setCellValue(MapUtils.getString(dzbzList.get(y), "DUTIES","")); for(int i=0;i<titleMergeCell+titleMergeCell+titleMergeCell-1;i++){ row9.createCell(i+2).setCellStyle(cellStyle); } CellRangeAddress region51 = new CellRangeAddress((rowIndex+3+y+1),(rowIndex+3+y+1),2,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region51); markIndex = rowIndex+3+y+1; } }else{ //循环遍历姓名,现职务,拟任职务 for(int y=0;y<1;y++){ HSSFRow row9=sheet.createRow(rowIndex+3+y+1); row9.setHeight((short)500); row9.createCell(0).setCellStyle(cellStyle); row9.createCell(1).setCellStyle(cellStyle); for(int i=0;i<titleMergeCell+titleMergeCell+titleMergeCell-1;i++){ row9.createCell(i+2).setCellStyle(cellStyle); } CellRangeAddress region51 = new CellRangeAddress((rowIndex+3+y+1),(rowIndex+3+y+1),2,(short) (titleMergeCell+titleMergeCell+titleMergeCell)); //给定要合并的单元格范围 sheet.addMergedRegion(region51); markIndex = rowIndex+3+y+1; } } String mark = "注:"+TALKRANGE; mark=mark+ "(此处根据实际填写),应到XX人,实到XX人;发出XX张票,收回XX票,全部有效。"; mark=mark+"n"+"统计人:"; mark=mark+"n"+"复核人:"; mark=mark+"n"+"工作组: "; mark=mark+"n"+"工作组组长(签字): "; mark=mark+"n"+TIME; //打印备注 HSSFRow row10=sheet.createRow(markIndex+1); row10.setHeight((short)500); //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 sheet.addMergedRegion(new Region(markIndex+1, (short) 0, markIndex+1, (short) (titleMergeCell+titleMergeCell+titleMergeCell))); HSSFCell cell02=row10.createCell(0); cell02.setCellValue(mark); cell02.setCellStyle(cellStyle1); //设置单元格高度 row10.setHeight((short)2000); } } if(Integer.parseInt(twoVoteFlag)>= 1){ //定义文件的输出流,但是这是作为zip流的一部分 ByteArrayOutputStream output = new ByteArrayOutputStream(); //流文件 String filename = "民主推荐票汇总(一轮)"; wb.write(output); //命名文件 zos.putNextEntry(new ZipEntry(filename+".xls")); response.setHeader("Content-disposition", "attachment; success=true; filename =" +new String(filename.getBytes("utf-8"),"iso-8859-1")+ ".zip"); //把xlsx输出流作为输入流输入到zip输出流中 zos.write(output.toByteArray()); zos.closeEntry(); output.close(); } if(Integer.parseInt(twoVoteFlag)>= 2){ //定义文件的输出流,但是这是作为zip流的一部分 ByteArrayOutputStream output = new ByteArrayOutputStream(); //流文件 String filename ="民主推荐票汇总(二轮)"; wb1.write(output); zos.putNextEntry(new ZipEntry(filename+".xls"));// 生成压缩文件的文件 response.setHeader("Content-disposition", "attachment; success=true; filename =" +new String(filename.getBytes("utf-8"),"iso-8859-1")+ ".zip"); //把xlsx输出流作为输入流输入到zip输出流中 zos.write(output.toByteArray()); zos.closeEntry(); output.close(); } zos.flush(); zos.close(); return null; } ======设置边框=setBorderStyle============= public void setBorderStyle(int border, CellRangeAddress region, HSSFSheet sheet, HSSFWorkbook wb){ RegionUtil.setBorderBottom(border, region, sheet, wb);//下边框 RegionUtil.setBorderLeft(border, region, sheet, wb); //左边框 RegionUtil.setBorderRight(border, region, sheet, wb); //右边框 RegionUtil.setBorderTop(border, region, sheet, wb); //上边框 }