ssm怎么导出数据库表为excel
2021/5/8 19:25:23
本文主要是介绍ssm怎么导出数据库表为excel,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
非常直白,请君自行饮用
//下载excel @RequestMapping("/downloadAllAppoint") @ResponseBody public String reprotRecord(HttpServletResponse response) throws IOException { // 文件名称 String fileName = URLEncoder.encode("刷卡记录.xlsx", "utf-8"); // 通过response设置Content-Type、Content-Disposition response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename*=utf-8'zh_cn'" + fileName); //生成workBook // HSSFWorkbook workbook = createWorkbook(); OutputStream outputStream = null; HSSFWorkbook workBook = null; try { // 获取输出流 outputStream = response.getOutputStream(); // 生成workBook workBook = downloadAllAppoint(); workBook.write(outputStream); } catch (IOException e) { e.printStackTrace(); } finally { //关闭 if (outputStream != null) { outputStream.close(); } } return null; } public HSSFWorkbook downloadAllAppoint() throws IOException { ///创建个空白的workbook[name:workbook] HSSFWorkbook workbook = new HSSFWorkbook(); //创建个空白的sheet[name:appoint] HSSFSheet sheet = workbook.createSheet("appoint"); //行 HSSFRow row; //单元格 HSSFCell cell; //创建行循环标签 int i = 0; //创建行 row = sheet.createRow(i); //列名标柱 cell = row.createCell(0); cell.setCellValue("预约编号"); cell = row.createCell(1); cell.setCellValue("预约用户账号"); cell = row.createCell(2); cell.setCellValue("用户名"); cell = row.createCell(3); cell.setCellValue("手机号"); cell = row.createCell(4); cell.setCellValue("预约项目"); cell = row.createCell(5); cell.setCellValue("预约时间"); cell = row.createCell(6); cell.setCellValue("预约状态"); //查询所有预约信息 List<Appoint> appointList = appointService.selectAllAppoint(); //开始循环 for (Appoint appoint : appointList) { i++; row = sheet.createRow(i); cell = row.createCell(0); cell.setCellValue(appoint.getAppoint_id()); cell = row.createCell(1); cell.setCellValue(appoint.getAppoint_userid()); cell = row.createCell(2); cell.setCellValue(appoint.getAppoint_username()); cell = row.createCell(3); cell.setCellValue(appoint.getAppoint_phonenum()); cell = row.createCell(4); cell.setCellValue(appoint.getAppoint_project()); cell = row.createCell(5); cell.setCellValue(appoint.getAppoint_time()); cell = row.createCell(6); cell.setCellValue(appoint.getAppoint_status()); } System.out.println("orderCondition.xls--[status:success]!"); return workbook; }
这篇关于ssm怎么导出数据库表为excel的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-29易优CMS安装常见问题汇总-icode9专业技术文章分享
- 2024-06-28易优新手必读安装教程-icode9专业技术文章分享
- 2024-06-28忘记eyoucms后台密码怎么办?-icode9专业技术文章分享
- 2024-06-26终极指南:Scrum中如何设置需求优先级
- 2024-06-26AI大模型企业应用实战(25)-为Langchain Agent添加记忆功能
- 2024-06-26小白家庭 nas 搭建方案-icode9专业技术文章分享
- 2024-06-23AI大模型企业应用实战(14)-langchain的Embedding
- 2024-06-23AI大模型企业应用实战(15)-langchain核心组件
- 2024-06-23AI大模型企业应用实战(16)-langchain核心组件
- 2024-06-23AI 大模型企业应用实战(06)-初识LangChain