EasyPOI实现excel文件导出

news/2024/7/21 5:59:41 标签: java, excel

EasyPOI真的是一款非常好用的文件导出工具,相较于传统的一行一列的数据导出,这种以实体类绑定生成的方式真的非常方便,也希望大家能够了解、掌握其使用方法,下面就用一个实例来简单介绍一下EasyPOI的使用。

1.导入依赖

        <!-- easypoi导出 -->
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>4.2.0</version>
        </dependency>

2.创建对应实体类

java">package com.wulian.training.center.export;

import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;

@Data
public class TestScoreExportDTO {
    /**
     * 序号
     */
    @Excel(name = "序号", orderNum = "1", width = 15)
    private Integer id;
    /**
     * 人员名称
     */
    @Excel(name = "人员名称", orderNum = "2", width = 15)
    private String personName;
    /**
     * 达标天数
     */
    @Excel(name = "达标天数", orderNum = "3", width = 15)
    private Integer passCount;
    /**
     * 积分总数
     */
    @Excel(name = "积分总数", orderNum = "4", width = 15)
    private String totalScore;
    /**
     * 日平均积分
     */
    @Excel(name = "日平均积分", orderNum = "5", width = 15)
    private String avgScore;
    /**
     * 积分排名
     */
    @Excel(name = "积分排名", orderNum = "6", width = 15)
    private Integer number;

}

3.导出方法
 

java">    @PostMapping("/export")
    @ApiOperation(value = "导出")
    public ResultMoudel export(@RequestParam(required = false)String name,HttpServletRequest request) throws IOException {

        Map map=new HashMap();
        map.put("name",name);
        map.put("companyId",sysUser.getCompanyId());
        List<TestScoreExportDTO> list=appTestManageMapper.selectOrderByTypePage(map);
        AtomicInteger id = new AtomicInteger(new Integer(1));
        list.stream().forEach(iter->{
                    iter.setId(id.getAndIncrement());
                });
        String fileName = "积分信息";
        //设置导出参数
        ExportParams exportParams = new ExportParams("积分信息", "排名", ExcelType.XSSF);
        //设置表头
        exportParams.setCreateHeadRows(true);
//        exportParams.setAddIndex(true);
        //数据渲染
        Workbook sheets = ExcelExportUtil.exportExcel(exportParams, TestScoreExportDTO.class, list);
        //导出
        final String downloadName = new String((fileName + ExcelTypeEnum.XLSX.getValue()).getBytes(), StandardCharsets.ISO_8859_1);
//        response.setCharacterEncoding("UTF-8");
        response.setHeader("content-Type", "application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=" + downloadName);
        //获取输出流,将excel输出
        ServletOutputStream outputStream = response.getOutputStream();
        sheets.write(outputStream);
        return new ResultMoudel<>().success("导出成功");

    }

 导出成功:


http://www.niftyadmin.cn/n/5177756.html

相关文章

PLC开发环境下载,安装方法

PLC开发环境下载&#xff0c;安装方法 一、200smart下载 1、S7-200.SMART.v2.7 百度网盘 请输入提取码 链接:https://pan.baidu.com/s/1hz56GEq66LG0kLP4jrzM5A 提取码&#xff1a;qm93 二、博途下载 1、博途V16 百度网盘 请输入提取码 链接&#xff1a;https://pan.b…

详细推导MOSFET的跨导、小信号模型、输出阻抗、本征增益

目录 前言 什么是跨导 什么是小信号模型 什么是输入阻抗和输出阻抗 什么是MOS管的输出阻抗 什么是MOS管的本征增益 共源极放大电路的输入和输出阻抗 一些其它MOS拓扑电路的增益 负载为恒流源 负载为二极管 前言 相信很多人在学习集成电路领域的时候 都对MOS管的…

[工业自动化-18]:西门子S7-15xxx编程 - 软件编程 - PLC用于工业领域的嵌入式系统:硬件原理图、指令系统、系统软件架构、开发架构等

目录 前言&#xff1a; 一、PLC的硬件电路原理 1.1 硬件框图 1.2 硬件模块详解 &#xff08;1&#xff09;CPU &#xff08;2&#xff09;存储器 &#xff08;3&#xff09;输入/输出&#xff08;I/O&#xff09;模块 &#xff08;4&#xff09;编程器 &#xff08;5&a…

PP-ChatOCRv2、PP-TSv2、大模型半监督学习工具...PaddleX新特性等你来pick!

小A是一名刚刚毕业的算法工程师&#xff0c;有一天&#xff0c;他被老板安排了一个活&#xff0c;要对一批合同扫描件进行自动化信息抽取&#xff0c;输出结构化的分析报表。OCR问题不大&#xff0c;但是怎么进行批量的结构化信息抽取呢&#xff1f;小A陷入了苦苦思索... 小B是…

【Android】画面卡顿优化列表流畅度四之Glide几个常用参数设置

好像是一年前快两年了&#xff0c;笔者解析过glide的源码&#xff0c;也是因为觉得自己熟悉一些&#xff0c;也就没太关注过项目里glide的具体使用对当前业务的影响&#xff1b;主要是自负&#xff0c;还有就是真没有碰到过这样的数据加载情况。暴露了经验还是不太足够 有兴趣的…

安装 Lua 的 HTTP 库

首先&#xff0c;你需要安装 Lua 的 HTTP 库。可以使用 LuaRocks 来安装。以下是安装命令&#xff1a; luarocks install http然后&#xff0c;你可以使用以下代码来爬取网页内容&#xff1a; local http require http-- 设置代理信息 http.set_proxy(jshk.com.cn)-- 网页UR…

【PyTorch教程】如何使用PyTorch分布式并行模块DistributedDataParallel(DDP)进行多卡训练

本期目录 1. 导入核心库2. 初始化分布式进程组3. 包装模型4. 分发输入数据5. 保存模型参数6. 运行分布式训练7. DDP完整训练代码 本章的重点是学习如何使用 PyTorch 中的 Distributed Data Parallel (DDP) 库进行高效的分布式并行训练。以提高模型的训练速度。 1. 导入核心库 D…

论文导读 | 图流的分割和摘要

前 言 本次论文导读介绍有关图流的分割和摘要问题的3篇文章。第1篇是partition的&#xff0c;第2篇是summarization的。 首先介绍第一篇文章。 文章一&#xff1a;图分割在分布式系统中有广泛的应用 文章的问题定义是用划分边的方式来分割图。如图所示&#xff0c;把图&#…