先上效果图


标题里的部门隐掉了,其实是有部门名称的

为保护隐私人员姓名也做了处理

这种考勤表相对复杂一些,看需求情况,有需求的可继续看下去

废话不多说 上才艺

1.查询考勤表数据的方法

/**
*查询考勤数据并将数据交给工具类执行
*/
public void expAttendanceExcel() {Employee employee = (Employee) getRequest().getSession().getAttribute(MyConstants.loginEmployee);// 获取当前登录用户SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//选择的年月String date = getRequest().getParameter("date")==null?sdf.format(new Date()):getRequest().getParameter("date").trim();String mrkqdeptId = employee.getDepartmentGuid();String deptName = employee.getDeptName();Map<String, Object> map = new HashMap<String, Object>();map.put("deptId", mrkqdeptId);map.put("deptName", deptName);String[] dates = date.split("-");String year = dates[0];String month = dates[1];map.put("year", Integer.parseInt(year));map.put("month", month);int count = dailyService.countDailyAttendance1(map);Paging.setPagingParams(getRequest(), count, count);map.put("pageIndex", Paging.pageIndex);List<DailyAttendance> list = this.dailyService.findDailyAttendanceList1(map, Paging.pageIndex, Paging.pageSize);List<Employee> empList = employeeService.findEmployeeListByDepId(mrkqdeptId);List<String[]> excelData = new ArrayList<String[]>();List<String[]> excelEmpData = new ArrayList<String[]>();Calendar c = Calendar.getInstance();c.set(Calendar.YEAR, Integer.parseInt(year));c.set(Calendar.MONTH, Integer.parseInt(month));int days = c.getActualMaximum(Calendar.DAY_OF_MONTH);String d = "";for(int i = 1;i <= days;i++) {d += i+",";}if(empList == null || empList.size()==0) {String[] temp = new String[] {};excelEmpData.add(temp);}else {for(Employee e : empList) {String[] temp = new String[] {e.getEmployeeName()};excelEmpData.add(temp);}}if (list==null || list.size()==0){/*String[] temp = new String[] {};excelData.add(temp);*/}else{for (DailyAttendance da : list) {String[] temp = new String[] {da.getDailyAttendanceTime(),da.getSxw(),da.getMrkqclockingNames(),da.getMrkqabsenteeismNames(),da.getMrkqsickNames(),da.getMrkqtravelNames(),da.getMrkqholidayNames(),da.getMrkqvisitNames(),da.getMrkqweddingNames(),da.getMrkqbirthNames()};excelData.add(temp);}}String title=date+deptName+"考勤表";String[] headers = new String[] { "姓名", "日期", d,"出勤天数",date};//生成考勤表的工具类ExcelOperationUtil.createComplicatedExcel(getResponse(), headers, excelData,excelEmpData, title);}

2.导出考勤表的工具类执行导出考勤表

/**
* 设置单元格样式
*/
public static HSSFCellStyle createCellStyle(HSSFWorkbook workbook, short fontsize,boolean flag,boolean flag1) {// TODO Auto-generated method stubHSSFCellStyle style = workbook.createCellStyle();//是否水平居中if(flag1){style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中}style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中//创建字体HSSFFont font = workbook.createFont();//是否加粗字体if(flag){font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);}else {font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);}font.setFontHeightInPoints(fontsize);//加载字体style.setFont(font);style.setBorderTop(HSSFCellStyle.BORDER_THIN);style.setBorderBottom(HSSFCellStyle.BORDER_THIN);style.setBorderLeft(HSSFCellStyle.BORDER_THIN);style.setBorderRight(HSSFCellStyle.BORDER_THIN);return style;
}/*** 设置合并单元格边框*/
private static void setBorderStyle(HSSFSheet sheet, CellRangeAddress region,HSSFWorkbook workbook) {// 合并单元格左边框样式RegionUtil.setBorderLeft(HSSFCellStyle.BORDER_THIN, region, sheet,workbook);// 合并单元格上边框样式RegionUtil.setBorderTop(HSSFCellStyle.BORDER_THIN, region, sheet,workbook);// 合并单元格右边框样式RegionUtil.setBorderRight(HSSFCellStyle.BORDER_THIN, region, sheet,workbook);// 合并单元格下边框样式RegionUtil.setBorderBottom(HSSFCellStyle.BORDER_THIN, region, sheet,workbook);
}/*** 计算日期的某天是星期几*/
public static String dateToWeek(String datetime) {SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");String[] weekDays = { "日", "一", "二", "三", "四", "五", "六" };Calendar cal = Calendar.getInstance(); // 获得一个日历Date datet = null;try {datet = f.parse(datetime);cal.setTime(datet);} catch (ParseException e) {e.printStackTrace();}int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。if (w < 0)w = 0;return weekDays[w];
}
public static void createComplicatedExcel(HttpServletResponse response,String[] headers, List<String[]> excelData,List<String[]> excelEmpData, String title){OutputStream outputStream = null;try {//清空responseresponse.reset();//需要此步骤//设置文件内容下载方式response.setHeader("Content-Disposition","attachment;filename="+toUtf8String(title+".xls"));//new String((title+".xls").getBytes("utf-8"), "iso-8859-1"));//设置以excel方式response.setContentType("application/vnd.ms-excel; charset=UTF-8");// 创建一个 workbook,对应一个Excel文件HSSFWorkbook workbook = new HSSFWorkbook();int sheetSize = 0;if (excelData.size()%60000>0){sheetSize = excelData.size()/60000+1;}else {sheetSize = excelData.size()/60000;}for (int z = 0;z<sheetSize;z++){// 在 workbook 中添加一个 sheet,对应 Excel 文件中的 sheetString sheetName = z*60000 + "-" + (z+1)*60000;if ((z+1)*60000 > excelData.size()){sheetName = z*60000 + "-" + excelData.size();}HSSFSheet sheet = workbook.createSheet("sheet1");//标题样式HSSFCellStyle titleStyle = createCellStyle(workbook,(short)20,true,true);//设置每列的宽度自适应sheet.autoSizeColumn(0);sheet.autoSizeColumn(1);for(int i = 0;i < headers[2].split(",").length;i++) {sheet.setColumnWidth(i+2, 4*256);}sheet.autoSizeColumn(headers[2].split(",").length+2);sheet.autoSizeColumn(headers[2].split(",").length+3);sheet.autoSizeColumn(headers[2].split(",").length+4);sheet.autoSizeColumn(headers[2].split(",").length+5);sheet.autoSizeColumn(headers[2].split(",").length+6);sheet.autoSizeColumn(headers[2].split(",").length+7);sheet.autoSizeColumn(headers[2].split(",").length+8);sheet.autoSizeColumn(headers[2].split(",").length+9);sheet.autoSizeColumn(headers[2].split(",").length+10);//合并单元格  标题//sheet.addMergedRegion(new Region((int)0 , (short) 0, (int)0, (short)(10+headers[2].split(",").length)));CellRangeAddress cr = new CellRangeAddress(0, 0, 0, (int)(10+headers[2].split(",").length));sheet.addMergedRegion(cr);//合并单元格 姓名//sheet.addMergedRegion(new Region((int)1 , (short) 0, (int)2, (short)0));CellRangeAddress cr1 = new CellRangeAddress(1, 2, 0, 0);sheet.addMergedRegion(cr1);//合并单元格 出勤天数//sheet.addMergedRegion(new Region((int)1 , (short)(headers[2].split(",").length+2), (int)1, (short)(headers[2].split(",").length+10)));CellRangeAddress cr2 = new CellRangeAddress(1,1,(int)(headers[2].split(",").length+2),(int)(headers[2].split(",").length+10));sheet.addMergedRegion(cr2);//合并单元格 人名int y = 0;for(int i = 0;i<excelEmpData.size();i++) {sheet.addMergedRegion(new Region((int)(y+3) , (short)0 , (int)(y+4), (short)0));y = y + 2;}//合并单元格 出勤、出差、病事假、公休假、探亲假、婚丧假、生育假、迟到早退、旷工int t = 0;for(int i = 0;i<excelEmpData.size();i++) {sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+2), (int)(t+4), (short)(headers[2].split(",").length+2)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+3), (int)(t+4), (short)(headers[2].split(",").length+3)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+4), (int)(t+4), (short)(headers[2].split(",").length+4)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+5), (int)(t+4), (short)(headers[2].split(",").length+5)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+6), (int)(t+4), (short)(headers[2].split(",").length+6)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+7), (int)(t+4), (short)(headers[2].split(",").length+7)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+8), (int)(t+4), (short)(headers[2].split(",").length+8)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+9), (int)(t+4), (short)(headers[2].split(",").length+9)));sheet.addMergedRegion(new Region((int)(t+3) , (short) (headers[2].split(",").length+10), (int)(t+4), (short)(headers[2].split(",").length+10)));t = t + 2;}//合并单元格 备注//sheet.addMergedRegion(new  Region((int)(excelEmpData.size()*2+3) , (short)0, (int)(excelEmpData.size()*2+3), (short)(headers[2].split(",").length+10)));CellRangeAddress crbz = new CellRangeAddress((int)(excelEmpData.size()*2+3), (int)(excelEmpData.size()*2+3), 0, (int)(headers[2].split(",").length+10));sheet.addMergedRegion(crbz);//第1行开始-------------------------------------------------------/*Calendar c = Calendar.getInstance();int month = c.get(Calendar.MONTH) + 1; //当前月份int year = c.get(Calendar.YEAR);c.set(Calendar.YEAR, year);c.set(Calendar.MONTH, month-2);  //上个月int monthNew = c.get(Calendar.MONTH)+1;int yearNew = c.get(Calendar.YEAR);*/String[] dates = headers[4].split("-");String year = dates[0];String month = dates[1];int monthNew = Integer.parseInt(month);int yearNew = Integer.parseInt(year);//第一行作为标题HSSFRow row0 = sheet.createRow((int) 0);//设置行高row0.setHeight((short)800);// 创建第 i 个单元格HSSFCell createCell = row0.createCell(0);// 给单元格赋值createCell.setCellValue(title);// 设置单元格格式createCell.setCellStyle(titleStyle);//第1行结束-------------------------------------------------------//第2行开始-------------------------------------------------------// 在 sheet 中添加第 2行(表头)HSSFRow row1 = sheet.createRow((int) 1);//表头样式HSSFCellStyle headStyle = createCellStyle(workbook,(short)11,false,true);// 创建第 1 个单元格 姓名HSSFCell row1Cell0 = row1.createCell(0);// 给单元格赋值row1Cell0.setCellValue(headers[0]);// 设置单元格格式row1Cell0.setCellStyle(headStyle);// 创建第 2 个单元格 日期HSSFCell row1Cell1 = row1.createCell(1);// 给单元格赋值row1Cell1.setCellValue(headers[1]);// 设置单元格格式row1Cell1.setCellStyle(headStyle);for(int i = 0;i<headers[2].split(",").length;i++) {//具体日期HSSFCell row1Celli = row1.createCell(i+2);row1Celli.setCellValue(headers[2].split(",")[i]);row1Celli.setCellStyle(headStyle);}//创建第33个单元格 出勤天数HSSFCell row1Cell33 = row1.createCell(headers[2].split(",").length+2);row1Cell33.setCellValue(headers[3]);row1Cell33.setCellStyle(headStyle);//第2行结束-------------------------------------------------------//第3行开始-------------------------------------------------------HSSFRow row2 = sheet.createRow((int) 2);// 创建第 1 个单元格 星期HSSFCell row2Cell1 = row2.createCell(1);// 给单元格赋值row2Cell1.setCellValue("星期");// 设置单元格格式row2Cell1.setCellStyle(headStyle);for(int i = 0; i < headers[2].split(",").length;i++) {String datetime = yearNew+"-"+monthNew+"-"+headers[2].split(",")[i];String week = dateToWeek(datetime);// 创建第 i 个单元格 星期几HSSFCell row2Celli = row2.createCell(i+2);// 给单元格赋值row2Celli.setCellValue(week);// 设置单元格格式row2Celli.setCellStyle(headStyle);}//创建第33个单元格 出勤HSSFCell row2Cell33 = row2.createCell(headers[2].split(",").length+2);row2Cell33.setCellValue("出勤");row2Cell33.setCellStyle(headStyle);//创建第34个单元格 出差HSSFCell row2Cell34 = row2.createCell(headers[2].split(",").length+3);row2Cell34.setCellValue("出差");row2Cell34.setCellStyle(headStyle);//创建第35个单元格 病事假HSSFCell row2Cell35 = row2.createCell(headers[2].split(",").length+4);row2Cell35.setCellValue("病、事假");row2Cell35.setCellStyle(headStyle);//创建第36个单元格 公休假HSSFCell row2Cell36 = row2.createCell(headers[2].split(",").length+5);row2Cell36.setCellValue("公休假");row2Cell36.setCellStyle(headStyle);//创建第37个单元格 探亲假HSSFCell row2Cell37 = row2.createCell(headers[2].split(",").length+6);row2Cell37.setCellValue("探亲假");row2Cell37.setCellStyle(headStyle);//创建第38个单元格 婚丧假HSSFCell row2Cell38 = row2.createCell(headers[2].split(",").length+7);row2Cell38.setCellValue("婚丧假");row2Cell38.setCellStyle(headStyle);//创建第39个单元格 生育假HSSFCell row2Cell39 = row2.createCell(headers[2].split(",").length+8);row2Cell39.setCellValue("生育假");row2Cell39.setCellStyle(headStyle);//创建第40个单元格 迟到、早退HSSFCell row2Cell40 = row2.createCell(headers[2].split(",").length+9);row2Cell40.setCellValue("迟到、早退");row2Cell40.setCellStyle(headStyle);//创建第41个单元格 旷工HSSFCell row2Cell41 = row2.createCell(headers[2].split(",").length+10);row2Cell41.setCellValue("旷工");row2Cell41.setCellStyle(headStyle);//第3行结束-------------------------------------------------------//数据行开始-------------------------------------------------------int w = 0;for(int i = 0; i < excelEmpData.size();i++) {double chuqincount = 0;  //出勤天数double chuchaicount = 0; //出差天数double bingshijiacount = 0; //病事假天数double gongxiucount = 0; //公休假天数double tanqincount = 0;   //探亲假天数double hunsangcount = 0;  //婚丧假天数double shengyucount = 0;  //生育假天数double chidaozaotuicount = 0;  //迟到早退天数double kuanggongcount = 0;  //旷工假天数HSSFRow row4 = sheet.createRow((int) w+3); //第4行HSSFRow row5 = sheet.createRow((int) w+4); //第5行//人名HSSFCell row4Cell0= row4.createCell(0);row4Cell0.setCellValue(excelEmpData.get(i)[0]);row4Cell0.setCellStyle(headStyle);HSSFCell row5Cell0= row5.createCell(0);HSSFCellStyle leftBorderStyle = workbook.createCellStyle();leftBorderStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);row5Cell0.setCellStyle(leftBorderStyle);//上午HSSFCell row4Cell1= row4.createCell(1);row4Cell1.setCellValue("上午");row4Cell1.setCellStyle(headStyle);//下午HSSFCell row5Cell1= row5.createCell(1);row5Cell1.setCellValue("下午");row5Cell1.setCellStyle(headStyle);//第4行 1号-31号for(int j = 0;j < headers[2].split(",").length;j++) {HSSFCell row4Cellj= row4.createCell(j+2);row4Cellj.setCellStyle(headStyle);row4Cellj.setCellType(Cell.CELL_TYPE_STRING);if(excelData != null && excelData.size()>0) {for(int k = 0; k < excelData.size();k++) {String[] rowData = excelData.get(k);if(rowData[0] != null || !rowData[0].equals("")) {String day = rowData[0].substring(rowData[0].length()-2, rowData[0].length()); //考勤日期String DAY = headers[2].split(",")[j]; //表格里的日期if(Integer.parseInt(day) == Integer.parseInt(DAY)) {if(rowData[2].contains(excelEmpData.get(i)[0])) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("△");chidaozaotuicount = chidaozaotuicount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("△");chidaozaotuicount = chidaozaotuicount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[3].contains(excelEmpData.get(i)[0])) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("×");kuanggongcount = kuanggongcount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("×");kuanggongcount = kuanggongcount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[4].contains(excelEmpData.get(i)[0])) {if(rowData[1].equals("上午") || rowData[1].equals("全天")) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("○");bingshijiacount = bingshijiacount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("○");bingshijiacount = bingshijiacount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[1].equals("下午")) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("√");chuqincount = chuqincount + 0.5;}}}else if(rowData[5].contains(excelEmpData.get(i)[0])) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("☆");chuchaicount = chuchaicount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("☆");chuchaicount = chuchaicount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[6].contains(excelEmpData.get(i)[0])) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("□");gongxiucount = gongxiucount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("□");gongxiucount = gongxiucount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[7].contains(excelEmpData.get(i)[0])) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("◇");tanqincount = tanqincount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("◇");tanqincount = tanqincount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[8].contains(excelEmpData.get(i)[0])) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("▲");hunsangcount = hunsangcount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("▲");hunsangcount = hunsangcount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[9].contains(excelEmpData.get(i)[0])) {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("▼");shengyucount = shengyucount + 0.5;}if(row4Cellj.getStringCellValue().equals("√")) {row4Cellj.setCellValue("▼");shengyucount = shengyucount + 0.5;chuqincount = chuqincount - 0.5;}}else {if(row4Cellj.getStringCellValue().equals("")) {row4Cellj.setCellValue("√");chuqincount = chuqincount + 0.5;}}}}}}}// 第5行 1号-31号for(int j = 0;j < headers[2].split(",").length;j++) {HSSFCell row5Cellj= row5.createCell(j+2);row5Cellj.setCellStyle(headStyle);row5Cellj.setCellType(Cell.CELL_TYPE_STRING);if(excelData != null && excelData.size()>0) {for(int k = 0; k < excelData.size();k++) {String[] rowData = excelData.get(k);if(rowData[0] != null || !rowData[0].equals("")) {String day = rowData[0].substring(rowData[0].length()-2, rowData[0].length()); //考勤日期String DAY = headers[2].split(",")[j]; //表格里的日期if(Integer.parseInt(day) == Integer.parseInt(DAY)) {if(rowData[2].contains(excelEmpData.get(i)[0])) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("△");chidaozaotuicount = chidaozaotuicount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("△");chidaozaotuicount = chidaozaotuicount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[3].contains(excelEmpData.get(i)[0])) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("×");kuanggongcount = kuanggongcount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("×");kuanggongcount = kuanggongcount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[4].contains(excelEmpData.get(i)[0])) {if(rowData[1].equals("下午") || rowData[1].equals("全天")) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("○");bingshijiacount = bingshijiacount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("○");bingshijiacount = bingshijiacount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[1].equals("上午")) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("√");chuqincount = chuqincount + 0.5;}}}else if(rowData[5].contains(excelEmpData.get(i)[0])) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("☆");chuchaicount = chuchaicount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("☆");chuchaicount = chuchaicount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[6].contains(excelEmpData.get(i)[0])) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("□");gongxiucount = gongxiucount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("□");gongxiucount = gongxiucount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[7].contains(excelEmpData.get(i)[0])) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("◇");tanqincount = tanqincount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("◇");tanqincount = tanqincount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[8].contains(excelEmpData.get(i)[0])) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("▲");hunsangcount = hunsangcount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("▲");hunsangcount = hunsangcount + 0.5;chuqincount = chuqincount - 0.5;}}else if(rowData[9].contains(excelEmpData.get(i)[0])) {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("▼");shengyucount = shengyucount + 0.5;}if(row5Cellj.getStringCellValue().equals("√")) {row5Cellj.setCellValue("▼");shengyucount = shengyucount + 0.5;chuqincount = chuqincount - 0.5;}}else {if(row5Cellj.getStringCellValue().equals("")) {row5Cellj.setCellValue("√");chuqincount = chuqincount + 0.5;}}}}}}}//出勤  HSSFCell row4Cellchuqin= row4.createCell(headers[2].split(",").length+2);row4Cellchuqin.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellchuqin.setCellValue(chuqincount);row4Cellchuqin.setCellStyle(headStyle);//出差  HSSFCell row4Cellchuchai= row4.createCell(headers[2].split(",").length+3);row4Cellchuchai.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellchuchai.setCellValue(chuchaicount);row4Cellchuchai.setCellStyle(headStyle);//病事假  HSSFCell row4Cellbingshijia= row4.createCell(headers[2].split(",").length+4);row4Cellbingshijia.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellbingshijia.setCellValue(bingshijiacount);row4Cellbingshijia.setCellStyle(headStyle);//公休假  HSSFCell row4Cellgongxiu= row4.createCell(headers[2].split(",").length+5);row4Cellgongxiu.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellgongxiu.setCellValue(gongxiucount);row4Cellgongxiu.setCellStyle(headStyle);//探亲假  HSSFCell row4Celltanqin= row4.createCell(headers[2].split(",").length+6);row4Celltanqin.setCellType(Cell.CELL_TYPE_NUMERIC);row4Celltanqin.setCellValue(tanqincount);row4Celltanqin.setCellStyle(headStyle);//婚丧假  HSSFCell row4Cellhunsang= row4.createCell(headers[2].split(",").length+7);row4Cellhunsang.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellhunsang.setCellValue(hunsangcount);row4Cellhunsang.setCellStyle(headStyle);//生育假  HSSFCell row4Cellshengyu= row4.createCell(headers[2].split(",").length+8);row4Cellshengyu.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellshengyu.setCellValue(shengyucount);row4Cellshengyu.setCellStyle(headStyle);//迟到早退  HSSFCell row4Cellchidaozaotui= row4.createCell(headers[2].split(",").length+9);row4Cellchidaozaotui.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellchidaozaotui.setCellValue(chidaozaotuicount);row4Cellchidaozaotui.setCellStyle(headStyle);//旷工  HSSFCell row4Cellkuanggong= row4.createCell(headers[2].split(",").length+10);row4Cellkuanggong.setCellType(Cell.CELL_TYPE_NUMERIC);row4Cellkuanggong.setCellValue(kuanggongcount);row4Cellkuanggong.setCellStyle(headStyle);//为没有右边框的格子设置右边框HSSFCellStyle rightBorderStyle = workbook.createCellStyle();rightBorderStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//出勤  HSSFCell row5Cellchuqin= row5.createCell(headers[2].split(",").length+2);row5Cellchuqin.setCellStyle(rightBorderStyle);//出差  HSSFCell row5Cellchuchai= row5.createCell(headers[2].split(",").length+3);row5Cellchuchai.setCellStyle(rightBorderStyle);//病事假  HSSFCell row5Cellbingshijia= row5.createCell(headers[2].split(",").length+4);row5Cellbingshijia.setCellStyle(rightBorderStyle);//公休假  HSSFCell row5Cellgongxiu= row5.createCell(headers[2].split(",").length+5);row5Cellgongxiu.setCellStyle(rightBorderStyle);//探亲假  HSSFCell row5Celltanqin= row5.createCell(headers[2].split(",").length+6);row5Celltanqin.setCellStyle(rightBorderStyle);//婚丧假  HSSFCell row5Cellhunsang= row5.createCell(headers[2].split(",").length+7);row5Cellhunsang.setCellStyle(rightBorderStyle);//生育假  HSSFCell row5Cellshengyu= row5.createCell(headers[2].split(",").length+8);row5Cellshengyu.setCellStyle(rightBorderStyle);//迟到早退  HSSFCell row5Cellchidaozaotui= row5.createCell(headers[2].split(",").length+9);row5Cellchidaozaotui.setCellStyle(rightBorderStyle);//旷工  HSSFCell row5Cellkuanggong= row5.createCell(headers[2].split(",").length+10);row5Cellkuanggong.setCellStyle(rightBorderStyle);w = w + 2;}//数据行结束----------------------------------------------------------//备注行开始----------------------------------------------------------HSSFRow rowbz = sheet.createRow((int) excelEmpData.size()*2+3); //备注行HSSFCell rowbzCell0= rowbz.createCell(0);rowbzCell0.setCellValue("备注:\"√\"出勤  \"△\"迟到、早退  \"×\"旷工  \"☆\"出差  \"○\"病、事假  \"□\"公休假  \"◇\"探亲假  \"▲\"婚丧假  \"▼\"生育假");HSSFCellStyle bzStyle = createCellStyle(workbook,(short)11,false,false);rowbzCell0.setCellStyle(bzStyle);//备注行结束----------------------------------------------------------//设置合并单元格边框 要放在最后 不然createRow()会覆盖已设置的边框setBorderStyle(sheet,cr, workbook);setBorderStyle(sheet,cr1, workbook);setBorderStyle(sheet,cr2, workbook);setBorderStyle(sheet,crbz, workbook);}// 创建输出流,并将 Excel 保存到本地outputStream = response.getOutputStream();// 将 workbook 写入输出流中workbook.write(outputStream);} catch (Exception e) {e.printStackTrace();} finally {try {// 关闭 outputStreamif(outputStream != null) {outputStream.flush();outputStream.close();}} catch (IOException e) {e.printStackTrace();}}}

这里先建议用excel画个空表格 然后照着空表格数行数和列数,这样创建行和列的时候不会乱,创建的行和列index从0开始数

后面的出勤、出差等天数统计看需求情况酌情增删就可以

打完收工!

几乎没人教你的用poi导出如此复杂的考勤表相关推荐

  1. POI导出word表格 office打开没问题 wps打开列有问题

    POI导出word表格 office打开没问题 wps打开列有问题 模板样式 导出文档office打开 wps打开文件 1.给表格设置宽,指定宽度 2.将布局固定 3.动态设置单元格的宽度 4.重点设 ...

  2. 使用poi导出大量数据到excel遇到的问题

    最近在工作遇到利用poi导出大量数据到excel并提供下载的运用场景,并遇到了一个问题,当数据量过大时(几十万),后台在进行数据写入excel中的过程会非常耗时,导致迟迟没有响应前台,结果数据还没导完 ...

  3. poi导出数据文件名错误_POI导出Excel报错“扩展名与文件的格式不匹配”

    下面是我用POI导出Excel的实例: 依赖的jar包 org.apache.poi poi 4.0.1 工具类 public class ExportExcel { // 显示的导出表的标题 pri ...

  4. SpringBoot Poi导出word,浏览器下载

    文章目录 SpringBoot Poi导出word,浏览器下载 1.引依赖: 2.写代码(生成本地word): 3.返回给浏览器下载 1.如何返回给浏览器让它下载 4.解决方案 5.为什么没使用eas ...

  5. java输出excel 异常处理_使用poi导出Excel,并设定单元格内容类型,抛出异常

    本例子使用的是HSSF,为Excel2003提供处理方案. 设定为输入类型为数值 import org.apache.poi.hssf.usermodel.DVConstraint; import o ...

  6. java使用poi导出ppt图表——环形图/空心饼图

    目录 前言 使用java poi导出图表,就是找不到环形图/空心饼图怎么做的(或者是我没找到),找到的都是饼图,柱图,线图等. 所以就简单说一下怎么导出的. 一.导入poi相关jar包 二.先创建ex ...

  7. POI导出Excel设置单元格背景色

    POI导出Excel设置单元格背景色 导出Excel的时候,没有设置背景色,用2003版本的Excel工具打开会出现文档单元格背景自动填充黑色的情况,没有找到好的解决方法,就主动给他填充一种颜色,问题 ...

  8. POI导出Excel (满满的干货啊)

    已经实现的POI导出Excel 步骤一:导入依赖 <dependency><groupId>org.apache.poi</groupId><artifact ...

  9. JAVA导出Excel通用工具类——第一篇:详细介绍POI 导出excel的多种复杂情况,包括动态设置筛选、动态合并横向(纵向)单元格等多种复杂情况——保姆级别,真的不能再详细了,代码拿来即用)

    JAVA导出Excel通用工具--第一篇:详细介绍POI 导出excel的多种复杂情况,包括动态设置筛选.动态合并横向(纵向)单元格等多种复杂情况--保姆级别,真的不能再详细了,封装通用工具类,代码拿 ...

  10. poi导出word2003(动态数据,不用模板,且生成word能再次导入)

    一.场景需求: 有个项目需要将某个题库里面的题目导出word2003,之前框架里面没有导出word2003的工具类.倒是见过导出txt,excel的,但是word的没有. 二.技术选型 网上找了一通, ...

最新文章

  1. 李白打酒c语言编程,搞定了“李白打酒”,还原问题都迎刃而解
  2. CoverageMeter中关于“line coverage”不准确的解释
  3. linux数组删除数据,JavaScript在数组的循环中删除元素
  4. Protocol Buffer序列化协议及应用
  5. 【bzoj2081】[Poi2010]Beads Hash
  6. nginx安装包_安装nginx与fastdfs-nginx-module
  7. go gorm框架一对多查询代码示例
  8. dw服务器文件夹在哪里,Dreamweaver CC
  9. leetcode 关于树的题目
  10. java压栈重复字符串_Java 实例 – 压栈出栈的方法实现字符串反转
  11. 计算机算法可分为两大类别_广东元耀:您了解过防水淋雨试验箱可分为哪几种类别吗?...
  12. 开源视频平台:ViMP
  13. 博士论文答辩||基于深度强化学习的复杂作业车间调度问题研究
  14. android软件安全权威指南 pdf_目录公众号内的所有资源软件!
  15. 内网穿透外网访问内网 MySQL 数据库教程
  16. python返回索引值_python取索引值
  17. Redis集群:主从节点添加和删除
  18. 川希:精准引流的本质,被动涨粉的秘密。
  19. html链接regard,regard是什么意思
  20. java判断胡牌_怎么写一个c++程序判断麻将是否胡牌(只讨论清一色的情况)

热门文章

  1. MATLAB利用ode求解二阶微分方程
  2. 蓝牙解码格式哪个最好_柏韵Pureaudio AirDSD Pro 串流播放解码前级
  3. 高德地图引入热力图插件失败
  4. HashMap底层实现原理概述
  5. HashMap底层原理与扩容机制
  6. Infinity 插件设置
  7. 数据仓库工具hive面试题集锦
  8. Unity下载安装及许可证获取教程
  9. 在服务器上安装centos系统
  10. python判断成语是abac型_abac型词语成语大全