使用easyexcel完成复杂表头及标题的导出功能(自定义样式)

该博客介绍了如何利用EasyExcel库在Java后端实现复杂表头和标题的Excel导出功能,包括设置自定义样式、内容样式策略、自动换行和字体大小。通过实体类注解法处理数据,控制器处理导出请求,并通过拦截器进行更精细的行高列宽设置。示例展示了如何根据客户端需求指定Excel版本。
摘要由CSDN通过智能技术生成

如需客户端指定excel版本,只需要判断后缀名然后在controller中的.excelType(ExcelTypeEnum.XLS)做指定输出内容格式即可
***(注意表格行高列宽统一设置是在实体类的类名注解上,如果需要对表格进行精细的宽高设置需要删除掉这两个注解,可以在拦截器使用row的方法进行设置)

1. ## 引入依赖

  1.     <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>easyexcel</artifactId>
        <version>2.1.4</version>
    </dependency>
    

2.实体类(注解法)

package com.jpxx.admin.pilebody.service.api.dto;
 
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.util.StringUtils;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
 
 
@Data
@NoArgsConstructor
@Accessors(chain = true)
@ContentRowHeight(45)
@HeadRowHeight(50)
public class PilebodycheckMonthDto {
 
    @ExcelIgnore
    private String id;
 
    @ExcelIgnore
    private String cityid;
 
    @ExcelIgnore
    private String districtid;
 
    @ExcelProperty(value = {"序号","序号"},index = 0)
    @ColumnWidth(10)
    private String orderNum;
 
    @ExcelProperty(value = {"堆体名称","堆体名称"},index = 1)
    @ColumnWidth(15)
    private String name;
 
    @ExcelProperty(value = {"具体位置","具体位置"},index = 3)
    @ColumnWidth(30)
    private String address;
 
    @ExcelProperty(value = {"占地面积(平方)","占地面积(平方)"},index = 4)
    @ColumnWidth(15)
    private String areastr;
 
    @ExcelProperty(value = {"堆体高度(
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值