EasyExcel实现多sheet模板导出

使用EasyExcel实现多sheet模板导出

依赖导入

我这边使用的是2.1.6,大家可以自行选择版本

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.1.6</version>
<dependency>

实体类

package com.ruoyi.system.domain.vo;

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.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 测试对象
 * 
 * @author wxl
 * @date 2024-04-18
 */
@ColumnWidth(25)
@ContentRowHeight(30)
@HeadRowHeight(50)
@Data
public class TestVo
{

    /** 签字日期 */
    @ExcelProperty(value = "签字日期")
    private String signTime;

    /** 填报日期 */
    @ExcelProperty(value = "填报日期")
    private String fillTime;
    
    /** 事由 */
    @ExcelProperty(value = "事由")
    private String reason;

    /** 类型 */
    @ExcelProperty(value = "类型")
    private String type;

    /** 申请人 */
    @ExcelProperty(value = "申请人")
    private String applicant;

    /** 经办人 */
    @ExcelProperty(value = "经办人")
    private String attn;

    /** 份数 */
    @ExcelProperty(value = "份数")
    private String num;

    /** 备注 */
    @ExcelProperty(value = "备注")
    private String remark;


}

多实体类文件导出

		//out为OutputStream
		ExcelWriter excelWriter = EasyExcelFactory.write(out).build();
        //设置内容样式
        WriteCellStyle contentStyle = new WriteCellStyle();
        contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//居中
        contentStyle.setWrapped(true);//自动换行
        //设置头部样式
        WriteCellStyle headerStyle = new WriteCellStyle();
        headerStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        //设置策略
        HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headerStyle, contentStyle);
        WriteSheet sheet1 = EasyExcelFactory.writerSheet(0, "sheetName1").head(TestVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
        WriteSheet sheet2 = EasyExcelFactory.writerSheet(1, "sheetName2").head(TestVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
        WriteSheet sheet3 = EasyExcelFactory.writerSheet(2, "sheetName3").head(TestVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
        // getWithSeal方法为获取当前sheet页所要填充的数据集合List
        excelWriter.write(getWithSeal(), sheet1 );
        excelWriter.write(getWithSeal(), sheet2 );
        excelWriter.write(getWithSeal(), sheet3 );
        excelWriter.finish();

以上便是使用EasyExcel实现多sheet页数据导出,感谢观看

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值