首页 > 代码库 > java 操作 Excel,java导出excel
java 操作 Excel,java导出excel
WritableWorkbook out = null; try { response.getServletResponse().reset(); ((HttpServletResponse) response.getServletResponse()).setHeader("Content-Disposition", "attachment;filename=export.xls"); response.getServletResponse().setContentType("gbk"); response.getServletResponse().setCharacterEncoding("gbk"); response.getServletResponse().setContentType("application/vnd.ms-excel"); out = Workbook.createWorkbook(((HttpServletResponse) response.getServletResponse()).getOutputStream()); int sheetNum = 0; WritableSheet sheet = out.createSheet("第1页", sheetNum); Label labels = null; String[] labea = { "员工唯一号", "员工姓名", "补差开始时间", "补差结束时间", "申报工资" }; for (int i = 0; i < labea.length; i++) { labels = new Label(i, 0, labea[i]); sheet.addCell(labels); } Label label = null; for (int i = 0; i < beans.size(); i++) { EmppostVo vo = (EmppostVo) beans.get(i); String emp_code = vo.getEmp_code() == null ? "" : vo.getEmp_code(); String emp_name = vo.getEmp_name() == null ? "" : vo.getEmp_name(); String startDate = vo.getStart_month() == null ? "" : vo.getStart_month().substring(0, 11); String endDate = vo.getEnd_month()== null ? "" : vo.getEnd_month().substring(0, 11); String baseSalary = vo.getBase_salary()== null ? "" : vo.getBase_salary(); String[] strArr = { emp_code, emp_name, startDate, endDate,baseSalary}; for (int j = 0; j < strArr.length; j++) { label = new Label(j, i + 1, strArr[j]); sheet.addCell(label); } } out.write(); } catch (RuntimeException e) { e.printStackTrace(); }finally{ out.close(); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。