EasyPoiUtil纯代码生成excel进行下载
前言:使用代码生成excel主要用于比较简单设计的excel,如需使用比较复杂的excel报表导出可看另外一篇文章
一.导入jar包
<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-base</artifactId><version>3.0.3</version><exclusions><exclusion><artifactId>commons-lang3</artifactId><groupId>org.apache.commons</groupId></exclusion><exclusion><artifactId>guava</artifactId><groupId>com.google.guava</groupId></exclusion></exclusions></dependency>
二.代码应用
导出的实体类属性(可利用@Excel设置单元格属性)
package com.xinke.sunshine_ebid.dal.entity;import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;@Data
public class TestEntity {@Excel(name = "姓名", orderNum = "1", width = 15)private String name;@Excel(name = "电话", orderNum = "2", width = 20)private String phone;@Excel(name = "地址", orderNum = "3", width = 30)private String address;
}
控制层
package com.xinke.sunshine_ebid.webapp;import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.xinke.sunshine_ebid.common.utils.EasyPoiUtils;
import com.xinke.sunshine_ebid.dal.entity.TestEntity;
import com.xinke.sunshine_ebid.service.TestService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;@CrossOrigin
@RestController
@RequestMapping(value = "/Test")
public class TestController {@Resourceprivate TestService testService;/*** 使用过代码直接生成excel表格* @param response* @throws Exception*/@GetMapping("/test")public void test(HttpServletResponse response) throws Exception{List<TestEntity> data = testService.test();EasyPoiUtils.exportExcel(data, null, "设置的表格名称", TestEntity.class,"设置的文件名称",response);}
}
业务逻辑层
package com.xinke.sunshine_ebid.service;import com.xinke.sunshine_ebid.dal.entity.TestEntity;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class TestService {public List<TestEntity> test() throws Exception{// 封装参数List<TestEntity> list = new ArrayList<>();TestEntity test = new TestEntity();test.setName("瓜");test.setPhone("18888888888");test.setAddress("PD");list.add(test);TestEntity test2 = new TestEntity();test2.setName("瓜2");test2.setPhone("1999999999");test2.setAddress("PD2");list.add(test2);return list;}
}
三.测试
调用接口
localhost:8087/Test/test
导出成功
EasyPoiUtil纯代码生成excel进行下载相关推荐
- 纯前端excel导出
文章目录 背景 技术选型 1.xlsx(`不满足`) 2.xlsx-style(`不推荐,后期问题太多`) 3.lay-excel(`推荐`) 一.准备内容数据 二.准备表头数据 三.认识lay-ex ...
- nginx,excel模板下载
nginx,excel模板下载 weixin_30814223 2018-08-27 10:26:00 245 收藏 版权 spring boot项目,使用nginx服务器 最近在做一个功能是ex ...
- 【vue+springboot】excel模板下载、导入功能实现
基于VUE+SpringBoot实现excel模板下载.导入功能 背景 最近在工作中经常遇到批量导入的功能,而且前端还要提示导入成功几条.失败几条.哪一条数据重复.是哪一条导入的数据出现问题等,抽空写 ...
- 微信小程序Excel生成下载浏览分享
微信小程序Excel生成下载浏览分享 完整流程 遇到的小问题 完整流程 主要是为了实现小程序前端从后端下载excel文件并浏览和分享excel文件给其他用户 主要实现步骤:通过后端返回的字节流 : w ...
- Office系列办公软件中的一款-Microsoft Excel提供下载
Excel表格是一款办公软件,一次突破传统表格的制作.Excel 2016是微软旗下Office系列办公软件中的一款,总体是以表格形式来运行,但是有很多功能都可以通过丰富的函数来实现,是一款上手简单, ...
- 将页面表格导出为excel并下载
将页面表格导出为excel并下载的方式有很多, 本次介绍的是表格div的下载. 这种方式很简单,不需要去创建excel文件,也不需要创建工作簿,然后一点一点的填写数据.只需要将页面的div中的表格下载 ...
- java迅雷下载excel,excel官方下载-excel2018 官方版
excel官方下载 excel 2018是一款功能强大的办公软件,是微软office 2018的组件,采用全新设计的用户界面.稳定安全的文件格式,无缝高效的沟通协作.方便用户制作表格数据.excel ...
- 【微信小程序】生成excel并下载 | 微信 | excel | 文件下载 |
生成excel并下载 有一个需求就是通过微信云数据库导出数据到excel并且下载到本地.首先对这个任务进行分解. 一 通过云数据库读取数据生成excel 在前端页面index.wxml添加按钮,绑定函 ...
- VUE+JAVA实现EXCEL模板下载
一.项目场景: VUE+JAVA实现EXCEL模板下载 二.功能背景 本人作为一个开发小白,今天接到一个小需求系统需要导入数据,也就十几个字段,我和老板说了,让客户一个一个去输入吧!然后我就被经理叫去 ...
最新文章
- Dokku和Docker的完美配合
- commons-beanutils的使用
- python minimize_Python数学规划案例一
- docker利用Dockerfile来制作镜像
- 苹果 5G 掉队?!
- NEW:5.9.4/Foxit PDF SDKfor ActiveX
- 百词斩不复习_不背单词好用还是百词斩好用?
- 大数据求中位数(插值计算)
- 毕业论文速成指南来了!
- 程序员不应该错过的 7 大导航
- D. Relatively Prime Graph codeforces 1009 D
- A Structure from Motion System
- TL-R406 IP带宽控制功能设置指南
- Python:数据降序排列索引
- Python+PyQt5实现灭霸响指
- 夏天CPU温度过高原因及解决办法
- mac mini u盘安装系统_用PE系统U盘启动盘安装操作系统
- 百度AI攻略:实现人体姿态判定打分
- 磨金石教育摄影技能干货分享:学会这些视频构图法手机也能拍大片
- 常用查找法(C语言)