java easyexcel 导出多级表头

maven

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>easyexcel</artifactId>
    <version>${easyexcel.version}</version>
</dependency>

导出行的对象

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;

import java.util.Date;

@Data
public class ExportItem {

    @ExcelProperty({"名称"})
    private String name;


    @ExcelProperty({"一级","二级头"})
    String data1;

    @ExcelProperty({"一级","二级头", "三级头","四级"})
    String data2;

    @ExcelProperty({"一级","二级头", "三级头","四级"})
    String data3;


    /**
     * 忽略这个字段
     */
    @ExcelIgnore
    private String ignoreData;
}

导出excel下载

// 导出excel
HttpServletResponse response;
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");

String fileName = "test_export";
fileName = URLEncoder.encode(fileName,"utf-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");


OutputStream outputStream = response.getOutputStream();
EasyExcel.write(outputStream,ExportItem.class).autoCloseStream(Boolean.FALSE).sheet(fileName).doWrite(exportItems);

文章来源地址https://uudwc.com/A/y5pYP

https://blog.csdn.net/weixin_51216079/article/details/119782920

原文地址:https://blog.csdn.net/wangooo/article/details/133134821

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年09月25日 09:37
18648 非洲猪瘟诊断技术
下一篇 2023年09月25日 09:37