Springboot项目结合miniui如何快速实现数据的导出到excel(Springboot项目结合miniui如何快速实现数据的导出到excel)
1.添加依赖

    <dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency>

2.导出功能控制层实现
@ApiOperation(value=“导出员工信息到excel”,notes="传递参数: ")
@ApiResponses({
@ApiResponse(code = 200, message = “操作成功”),
@ApiResponse(code = 500, message = “服务器错误”),
@ApiResponse(code = 404, message = “请求路径没有或者页面跳转路径错误”)
})
@RequestMapping(value = “/exportRyXxToExcel”,method = {RequestMethod.POST})
public void exportRyXxToExcel(@RequestParam(“columns”)String columns,
@RequestParam(“name”)String name,
@RequestParam(“ygbh”)String ygbh,
@RequestParam(“selectType”)String selectType,
@RequestParam(“selectValue”)String selectValue,
@RequestParam(“bmbh”)String bmbh,
@RequestParam(“bmlb”)String bmlb,
HttpServletResponse response){
uploadService.exportExcel(columns, name, ygbh, selectType, selectValue, bmbh, bmlb, response);

3.编写业务层接口
/**
* 导出数据到
* @param columns
* @param name
* @param ygbh
* @param selectType
* @param selectValue
* @param bmbh
* @param bmlb
*/
void exportExcel(String columns, String name, String ygbh, String selectType, String selectValue, String bmbh, String bmlb, HttpServletResponse response);

4.编写业务逻辑实现
@Override
public void exportExcel(String columns, String name, String ygbh, String selectType, String selectValue, String bmbh, String bmlb, HttpServletResponse response) {
JSONArray array = JSONArray.parseArray(columns);
//移除序号项
//array.remove(0);
//这里获取要导出的数据列
//1.可以通过前端传递
//2.可以直接从数据库中查询
List allPtYgMessage = cmsMapper.findAllPtYgMessage(null);

    try {OutputStream out = response.getOutputStream();String fname = "sheet1";response.reset();//清空输出流response.setCharacterEncoding("UTF-8");//设置相应内容的编码格式fname = java.net.URLEncoder.encode(fname, "UTF-8");response.setHeader("Content-Disposition", "attachment;filename=" + new String(fname.getBytes("UTF-8"), "GBK") + ".xls");response.setContentType("application/ms-excel");//定义输出类型//创建工作簿XSSFWorkbook workbook = new XSSFWorkbook();//创建工作表XSSFSheet sheet = workbook.createSheet(fname);//设置默认行宽sheet.setDefaultColumnWidth(20);//设置标题样式XSSFCellStyle cellStyle1 = workbook.createCellStyle();cellStyle1.setAlignment(HorizontalAlignment.CENTER);//水平居中cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中XSSFFont font = workbook.createFont();font.setFontHeightInPoints((short) 14);  //标题字大小font.setBold(true);  //加粗cellStyle1.setFont(font);//设置标题XSSFRow title = sheet.createRow(0);title.setHeightInPoints(20);  //行高XSSFCell cell = title.createCell(0);cell.setCellValue("检测平台人员基本信息");cell.setCellStyle(cellStyle1);//合并单元格sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));//设置表头样式XSSFCellStyle cellStyle2 = workbook.createCellStyle();cellStyle2.setAlignment(HorizontalAlignment.CENTER);//水平居中cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中//创建表头行和列名XSSFRow row = sheet.createRow(1);for (int i = 0; i < array.size(); i++) {XSSFCell columnHead = row.createCell(i);columnHead.setCellValue(array.getJSONObject(i).getString("header"));columnHead.setCellStyle(cellStyle2);}//设置数据行样式XSSFCellStyle cellStyle3 = workbook.createCellStyle();cellStyle3.setAlignment(HorizontalAlignment.CENTER);//水平居中cellStyle3.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中cellStyle3.setWrapText(true);//创建数据行//创建数据行for(int j = 0; j < allPtYgMessage.size(); j++){XSSFRow dataRow = sheet.createRow(j+2);XSSFCell cell0 = dataRow.createCell(0);XSSFCell cell1 = dataRow.createCell(1);XSSFCell cell2 = dataRow.createCell(2);XSSFCell cell3 = dataRow.createCell(3);XSSFCell cell4 = dataRow.createCell(4);XSSFCell cell5 = dataRow.createCell(5);XSSFCell cell6 = dataRow.createCell(6);XSSFCell cell7 = dataRow.createCell(7);XSSFCell cell8 = dataRow.createCell(8);XSSFCell cell9 = dataRow.createCell(9);XSSFCell cell10 = dataRow.createCell(10);cell0.setCellStyle(cellStyle3);cell1.setCellStyle(cellStyle3);cell2.setCellStyle(cellStyle3);cell3.setCellStyle(cellStyle3);cell4.setCellStyle(cellStyle3);cell5.setCellStyle(cellStyle3);cell6.setCellStyle(cellStyle3);cell7.setCellStyle(cellStyle3);cell8.setCellStyle(cellStyle3);cell9.setCellStyle(cellStyle3);cell10.setCellStyle(cellStyle3);cell0.setCellValue(allPtYgMessage.get(j).getName());   //姓名cell1.setCellValue(allPtYgMessage.get(j).getLbmc());  //    所属中心cell2.setCellValue(allPtYgMessage.get(j).getBmmc()); //所在部门cell3.setCellValue(allPtYgMessage.get(j).getSex()); //性别cell4.setCellValue(allPtYgMessage.get(j).getBirthday()); //生日cell5.setCellValue(allPtYgMessage.get(j).getDuty_name()); //职务cell6.setCellValue(allPtYgMessage.get(j).getXueli()); //最高学历cell7.setCellValue(allPtYgMessage.get(j).getZymx()); //学历及专业明细cell8.setCellValue(allPtYgMessage.get(j).getZhich()); //职称cell9.setCellValue(allPtYgMessage.get(j).getCzqk()); //持证情况cell10.setCellValue(allPtYgMessage.get(j).getBz()); //备注}workbook.write(out);//释放空间out.close();workbook.close();}catch (Exception e){e.printStackTrace();}
}

5.亲测有效,欢迎大家学习

Springboot项目结合miniui如何快速实现数据的导出到excel相关推荐

  1. 第六期:如何通过知晓云将数据表导出为 Excel 文件

    作者:知晓云 - 小程序开发快人一步 来源:知晓课堂 在日常的工作中,常常需要根据运营需求对数据进行各种格式的处理和导出.导出后,不少人偏爱将数据放入 excel在进行处理. 一般来说,处理数据导出时 ...

  2. TP5使用PHPExcel将数据动态导出为Excel表格

    数据表导出为Excel是CMS系统中很常见的功能,PHPExcel即使已经被作者停更但是依然是一个很好的选择,首先要知道的是PHPExcel不支持Composer下载,所以我们需要去Github中手动 ...

  3. java中将查询数据导出_如何在R中将数据框导出到Excel

    java中将查询数据导出 What if I tell, that you can export data frames to excel in R within a couple of minute ...

  4. iview table数据直接导出_(excel表格数据导入导出)iView如何实现excel导入导出

    请问:ERP系统的数据怎么导出Excel和Excel的数据怎么导入ERP? 一般的方法是: 在你找那个数据页面会有数据输出选项--点击 然后到登陆ERP的第一个远程桌面,会有一个资料夹 (各公司的命名 ...

  5. JAVA实现数据库数据导入/导出到Excel(POI)

    原文地址为: JAVA实现数据库数据导入/导出到Excel(POI) 准备工作: 1.导入POI包:POI下载地址http://mirrors.tuna.tsinghua.edu.cn/apache/ ...

  6. springBoot项目在Linux中快速启动

    文章目录 前言 一.windows环境 命令行启动常见问题及解决方案 1.1 没有主清单属性 1.2 端口冲突解决方案 二.Linux环境 启动常见问题及解决方案 1.如何后台启动? 2.启动后如何关 ...

  7. node爬取app数据_node爬取拉勾网数据并导出为excel文件

    前言 之前断断续续学习了node.js,今天就拿拉勾网练练手,顺便通过数据了解了解最近的招聘行情哈!node方面算是萌新一个吧,希望可以和大家共同学习和进步. 一.概要 我们首先需要明确具体的需求: ...

  8. php数据的导出到excel,php 数据的导出到excel表格-怎么将php数据导出excel

    怎么使用php把表格中的数据导入到excel中 下面写的一个PHP导出数据到CSV问价的函数,你到时候直接调用了 /** * 导出CSV * @param string $fileName文件名字 * ...

  9. 物联网设备数据流转之数据如何导出:Excel文件

    背景 其实,到现在为止,前面的页面已经实现了对设备数据的展现.这一篇文章中对当前的项目做一个增强: 绘制Echarts 图表展示数据变化趋势: 导出设备数据到Excel,体验TDengine的查询效率 ...

最新文章

  1. 算法(2)KMP算法
  2. unity替换mesh测试
  3. Xamarin iOS开发实战上册(内部资料daxueba.net)
  4. python 解析xml格式_Python解析XML文件
  5. flash调用swf文件服务器,浏览器如何加载Flash文件? (SWF)
  6. linux 在家工作_我如何调整在家工作的习惯
  7. Java-控制台接受用户输入数据的方法
  8. Jenkins学习总结(4)——持续集成,持续交付,持续部署之间的区别
  9. 恶意软件利用Windows故障诊断平台传播
  10. 请教如何实现UITextField值变化的实时监视
  11. Ajax核心:XMLHTTP组件相关技术资料
  12. 年终总结:我的2016
  13. 数据库SQL语言从入门到精通--Part 1--SQL语言概述
  14. sqlserver行列转换,动态行转换
  15. MGS摄像头:USF56S335_3238_V2 IMX335 5MP UVC应用手册
  16. php 判断百度蜘蛛抓取,百度蜘蛛抓取不存在目录 对应的解决方法
  17. 解决docker容器中使用composer,无法解析安装包
  18. S5PV210中断的介绍与配置
  19. 移动App该怎样保存用户password
  20. 写一个strncpy(char *dest, const char *src, size_t cpy_lent) 的函数

热门文章

  1. android app 测试方法,Android App常用性能指标测试方法
  2. 发现淘宝的一个bug
  3. CreateWindow与CreateWindowEx函数详解
  4. c语言字节数组转化成字符串,C语言 字节数组转为字符串
  5. Preview使用技巧,强大的macOS原生应用:「预览」(Preview)
  6. Mybatis注解方式@Insert
  7. 商盾商标查询接口缓慢原因
  8. ubuntu18.04 无法外接显示屏
  9. 上课笔记-机器学习(3)-省市消费聚类和人脸识别
  10. java画蝴蝶_java之数组