easypoi-springboot/springmvc导出数据为Excel
来源:互联网 发布:杭州市大数据管理局 编辑:程序博客网 时间:2024/06/07 19:56
easypoi功能如同名字easy,主打的功能就是容易,让一个没见接触过poi的人员 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 语言(熟悉的表达式语法),完成以前复杂的写法
官方资料
http://git.oschina.net/jueyue/easypoi
1.Maven中添加依赖
<!--easypoi导出excel--> <!--easypoi-base 导入导出的工具包,可以完成Excel导出,导入,Word的导出,Excel的导出功能--> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-base</artifactId> <version>2.3.1</version> </dependency> <!--easypoi-web 耦合了spring-mvc 基于AbstractView,极大的简化spring-mvc下的导出功能--> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-web</artifactId> <version>2.3.1</version> </dependency> <!--easypoi-annotation 基础注解包,作用与实体对象上,拆分后方便maven多工程的依赖管理--> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-annotation</artifactId> <version>2.3.1</version> </dependency>
2 POJO中添加注解
@Entity@Table(name = "user")@ExcelTarget("user")public class User { @Id @GeneratedValue @Excel(name = "编号", orderNum = "1", mergeVertical = true, isImportField = "id") private Long id; @Excel(name = "姓名", orderNum = "2", mergeVertical = true, isImportField = "name") private String name; @Excel(name = "年龄", orderNum = "3", mergeVertical = true, isImportField = "age")
3 Controller中请求
// 下载execl文档 @RequestMapping("/downloadExcel") public void download(HttpServletRequest request, HttpServletResponse response) throws Exception { // 告诉浏览器用什么软件可以打开此文件 response.setHeader("content-Type", "application/vnd.ms-excel"); // 下载文件的默认名称 response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("用户数据表","UTF-8") + ".xls"); //编码 response.setCharacterEncoding("UTF-8"); List<User> list = userService.findAll(); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), User.class, list); workbook.write(response.getOutputStream()); }
4 前端页面添加Button
<input type="button" value="导出为Excel" onclick="window.open('/downloadExcel');"/>
关于更多easypoi的注解和功能,请参看http://git.oschina.net/jueyue/easypoi ,easypoi对springmvc支持很好!可以导出数据为word/excel/pdf等各种格式.
阅读全文
7 0
- easypoi-springboot/springmvc导出数据为Excel
- springboot easypoi导出excel
- SpringMVC/SpringBoot使用easypoi实现Excel文件导入导出功能实现
- easypoi导出Excel
- Easypoi模版导出excel
- java easypoi导出Excel表格
- 关于easyPOI导出Excel功能
- SpringBoot+AngularJS导出数据库数据到excel
- EasyPoi 模板语法介绍,POI 的Excel模板导出
- Spring Boot 菜鸟教程 12 EasyPoi导出Excel下载
- EasyPOI->模版形式导出Excel(多Sheet)
- DataGridView数据导出为Excel
- DataGridView 数据导出为EXCEL
- plsql 导出数据为excel
- 导出数据为excel表格
- 列表数据导出为Excel
- java-SpringMVC框架导出Excel格式数据
- SpringBoot poi 导出Excel
- 点分治
- Android之Activity
- MVC,MVP,MVVM的区别和联系
- python 获取某个目录字段下的子目录或文件
- Leetcode 134. Gas Station
- easypoi-springboot/springmvc导出数据为Excel
- C++继承和多态
- JS--乱 <一>
- 【BZOJ】3314 [Usaco2013 Nov]Crowded Cows (多种解法)
- 金刚狼3:殊死一战 Logan (2017)
- 【NOI2011T6】兔兔与蛋蛋的游戏-二分图最大匹配+博弈
- java 文件类操作
- windows10+anaconda2+xgboost0.6的安装,VS和MinGW两种方式
- codeforces 814 B An express train to reveries