微信小程序> 员工签到软件-OA系统:实现员工签到表导出xs-签到小程序

员工签到软件-OA系统:实现员工签到表导出xs-签到小程序

浏览量:2480 时间: 来源:fachew

1.一、准备poiApachePOI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对MicrosoftOffice格式档案读和写的功能。二、修改视图层,给导出按键添加单击事件

//给导出按钮绑定单击事件$("#btn2").click(function(){alert("1");//获取三个查询条件的值varempId=$("#empId").val();vardeptno=$("#deptno").val();vardtDate=$("#dtDate").val();//访问指定的Servlet而不是用ajax,因为ajax是通过回调函数处理结果的,导出返回的是流,所以也不用转发和重定向location.href="servlet/DutyServlet?method=exportXls&empId="+empId+"&deptno="+deptno+"&dtDate="+dtDate;});

2.三、servlet添加exportEls和createExcel方法

//导出XLSpublicvoidexportXls(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//获取请求中的信息StringempId=request.getParameter("empId");Stringsdeptno=request.getParameter("deptno");intdeptno=0;try{deptno=Integer.parseInt(sdeptno);}catch(NumberFormatExceptione){//TODO:handleexceptione.printStackTrace();}StringsdtDate=request.getParameter("dtDate");java.sql.DatedtDate=null;try{dtDate=java.sql.Date.valueOf(sdtDate);}catch(RuntimeExceptione){//TODO:handleexceptione.printStackTrace();}//调用业务层完成业务操作DutyServicedutyService=newDutyServiceImpl();ListDutydutyList=dutyService.findDuty(empId,deptno,dtDate);//导入到Xls中createExcel(dutyList,response);}privatestaticvoidcreateExcel(ListDutylist,HttpServletResponseresponse){//创建一个Excel文件HSSFWorkbookworkbook=newHSSFWorkbook();//创建一个工作表HSSFSheetsheet=workbook.createSheet("考勤信息");CellRangeAddressregion=newCellRangeAddress(0,//firstrow0,//lastrow0,//firstcolumn2//lastcolumn);sheet.addMergedRegion(region);HSSFRowhssfRow=sheet.createRow(0);HSSFCellheadCell=hssfRow.createCell(0);headCell.setCellValue("考勤信息");//设置单元格格式居中HSSFCellStylecellStyle=workbook.createCellStyle();cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);headCell.setCellStyle(cellStyle);//添加表头行hssfRow=sheet.createRow(1);//添加表头内容headCell=hssfRow.createCell(0);headCell.setCellValue("用户名");headCell.setCellStyle(cellStyle);headCell=hssfRow.createCell(1);headCell.setCellValue("真实姓名");headCell.setCellStyle(cellStyle);headCell=hssfRow.createCell(2);headCell.setCellValue("所属部门");headCell.setCellStyle(cellStyle);headCell=hssfRow.createCell(3);headCell.setCellValue("出勤日期");headCell.setCellStyle(cellStyle);headCell=hssfRow.createCell(4);headCell.setCellValue("签到时间");headCell.setCellStyle(cellStyle);headCell=hssfRow.createCell(5);headCell.setCellValue("签退时间");headCell.setCellStyle(cellStyle);//添加数据内容for(inti=0;ilist.size();i++){hssfRow=sheet.createRow((int)i+2);Dutyduty=list.get(i);//创建单元格,并设置值HSSFCellcell=hssfRow.createCell(0);cell.setCellValue(duty.getEmp().getEmpId());cell.setCellStyle(cellStyle);cell=hssfRow.createCell(1);cell.setCellValue(duty.getEmp().getRealName());cell.setCellStyle(cellStyle);cell=hssfRow.createCell(2);cell.setCellValue(duty.getEmp().getDept().getDeptname());cell.setCellStyle(cellStyle);cell=hssfRow.createCell(3);cell.setCellValue(duty.getDtDate());cell.setCellStyle(cellStyle);cell=hssfRow.createCell(4);cell.setCellValue(duty.getSigninTime());cell.setCellStyle(cellStyle);cell=hssfRow.createCell(5);cell.setCellValue(duty.getSignoutTime());cell.setCellStyle(cellStyle);}//保存Excel文件try{response.setContentType("application/vnd.ms-excel");response.setHeader("Content-disposition","attachment;filename=duty.xls");//附件形式下载,文件名叫duty.xls//OutputStreamoutputStream=newFileOutputStream("D:/duty.xls");//保存到本地(服务器端)OutputStreamoutputStream=response.getOutputStream();//写到客户端workbook.write(outputStream);outputStream.close();}catch(Exceptione){e.printStackTrace();}}

3.四、运行图

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎