easyexcel模板填充列表

引入依赖

xml 复制代码
   <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.2.6</version>
        </dependency>

编写模板

编写代码

java 复制代码
public class FillData {

    private String name;
    private Double number;

    public FillData(String name, Double number) {
        this.name = name;
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getNumber() {
        return number;
    }

    public void setNumber(Double number) {
        this.number = number;
    }
}

注意:列表填充一定要用实体对象,不能用map

java 复制代码
    @RequestMapping("/test")
    public void test() {
   
        // 模板注意 用{} 来表示你要用的变量,{.}表示列表 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
        String templateFileName = "D:\\tools\\code\\excel\\demofillsimple.xlsx";


    
        String fileName = "D:\\tools\\code\\excel\\simpleFill" + System.currentTimeMillis() + ".xlsx";
        
        List<FillData> list = new ArrayList<>();

        FillData s1 = new FillData("张三", 20.0);
        FillData s2 = new FillData("李四", 50.0);
        list.add(s1);list.add(s2);
        FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
        ExcelWriter writer = EasyExcel.write(fileName).withTemplate(templateFileName).build();
        WriteSheet sheet1 = EasyExcel.writerSheet().sheetName("1").build();
        // 这里 会填充到第一个sheet页为名称为 1, 
        writer.fill(list,fillConfig,sheet1);
        WriteSheet sheet2 = EasyExcel.writerSheet().sheetName("2").build();
        // 这里 会填充到第一个sheet页为名称为 2, 
        writer.fill(list,fillConfig, sheet2);
        writer.finish();

    }

验证


相关推荐
the3clipse11 小时前
MPC-HC 下载安装与最佳配置教程:免费开源、轻量无广告、支持 4K 硬解的 Windows 播放器
windows·播放器·安装教程·硬件加速·mpc-hc·字幕设置·lav filters
独隅11 小时前
WebStorm Windows 版 React / Next.js 实战替换指南
javascript·windows·webstorm
陈工大模型11 小时前
2026年11月最新免费解压软件横评:7-Zip 、 Win解压缩名列前茅
windows·软件工程·7-zip·压缩软件
中二骚年1 天前
Windows 安全中心 / 防火墙故障,calc和Microsoft Store,终端(管理员)无法正常打开。 原因 + 修复方案
windows·安全·microsoft
万联WANFLOW2 天前
CVE-2026-98432 等漏洞自查:AI 查出的 Linux、Windows 漏洞,运维怎么确认受不受影响
linux·运维·windows·网络安全
AlanAshley2 天前
Windows 中导致延迟的软硬件及协议比重
windows
yuezhilangniao2 天前
win10中文 以及 PowerShell 开发日常
windows·powershell
共享家95272 天前
408 操作系统第一章
服务器·数据库·windows
Sakura_j_h_2 天前
GitHub Actions 打包 Windows exe:中文编码与产物上传
windows·ci/cd·打包发布·github·pyinstaller·github actions
xixiaoyunya2 天前
搭一个浏览器即用的二进制文件分发点:目录规范与权限边界实践
网络·windows