当前位置: 首页 > news >正文

Easypoi实现导出Excel(简单高效)

今天做报表导出,网上找了很多导出的方法,最后总结发现以下方法是最简便,更易维护的导出方法,下面来分享给大家。

1、首先引入相关依赖

        <!--EasyPoi 报表--><dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-spring-boot-starter</artifactId><version>4.4.0</version></dependency>

2、导出实体映射类

@Data
public class StudentReportResponse implements Serializable {@Excel(name = "性别", width = 12)private String gender;@Excel(name = "姓名", width = 15)private String name;
}

3、Controller层代码

    @GetMapping("/exportReport")@ApiOperation("导出学生报表")public void export(ModelMap map, HttpServletResponse response, HttpServletRequest request){try {List<StudentReportResponse> studentReportData = new ArrayList<>();StudentReportResponse student = new StudentReportResponse();student.setGender("男");student.setName("测试用户");studentReportData.add(student);ExportParams params = new ExportParams("学生报表", "学生报表", ExcelType.HSSF);map.put(NormalExcelConstants.DATA_LIST, studentReportData);map.put(NormalExcelConstants.CLASS, StudentReportResponse.class);map.put(NormalExcelConstants.PARAMS, params);map.put(NormalExcelConstants.FILE_NAME, "学生报表");PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);} catch (Exception e) {logger.error("导出学生报表报错:", e);}}

怎么样,是不是很简洁,可读性很高 ღ( ´・ᴗ・` )

http://www.lryc.cn/news/322612.html

相关文章:

  • python之pathlib库使用介绍
  • Java:设计模式
  • 【链表】Leetcode 19. 删除链表的倒数第 N 个结点【中等】
  • 亚马逊认证考试系列 - 知识点 - 安全组简介
  • 同向双指针合集(力扣)
  • G - Find a way
  • AJAX 02 案例、Bootstrap框架
  • SinoDB客户端工具dbaccess
  • postman学习
  • 【Linux】初识进程
  • 有关Theano和PyTensor库
  • 用 Open-Sora 高效创作视频,让创意触手可及
  • Git版本管理工具
  • 微信小程序选择器picker的使用(省市区)
  • std::shared_ptr与std::make_unique在类函数中的使用
  • flutter 局部view更新,dialog更新进度,dialog更新
  • Lombok:@Delegate优化代码利器
  • 【C语言】对称密码——栅栏的加密和解密
  • 一、rv1126开发之视频输入和视频编码
  • 4.1 用源文件写汇编代码
  • Linux TCP参数——tcp_abort_on_overflow
  • jupyter notebook设置代码提示方法
  • Linux 一点查询资料
  • 如何快速搭建一个完整的vue2+element-ui的项目-二
  • 多语言LLM的状态:超越英语
  • kafka什么情况下会认为发送失败进而去重试
  • 不满足软件包要求‘transformers==4.30.2‘, ‘sse-starlette
  • C# 设置AutoScroll为true没效果的原因分析和解决办法
  • <Senior High School Math>: inequality question
  • 详解Python中Pytest和Unittest的区别