easyexcel 合并单元格

本文详细介绍并演示了如何使用EasyExcel的ContentLoopMerge和OnceAbsoluteMerge注解进行单元格的合并操作,通过具体示例代码展示了如何在导出Excel表格时实现数据的行和列合并,适用于批量数据处理场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


easyexcel 合并单元格

 

 

*********************

相关注解

 

ContentLoopMerge:标注在字段上

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ContentLoopMerge {

    int eachRow() default -1;      //合并行
    int columnExtend() default 1;  //合并列
}

 

OnceAbsoluteMerge:标注在类上

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface OnceAbsoluteMerge {

    int firstRowIndex() default -1;      //初始行
    int lastRowIndex() default -1;       //最后一行

    int firstColumnIndex() default -1;   //初始列
    int lastColumnIndex() default -1;    //最后一列
}

 

 

*********************

示例

 

Test

@Data
class Book{

    @ContentLoopMerge(eachRow = 2)
    private Integer id;

    private String name;

    private Double price;
}

public class Test {

    private static final String write_path="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"write.xlsx";

    public static void write(){
        List<Book> list=new ArrayList<>();

        for (int i=0;i<5;i++){
            Book book=new Book();
            book.setId(i);
            book.setName("海贼王"+i);
            book.setPrice((double)(i+10));

            list.add(book);
        }

        EasyExcel.write(write_path,Book.class).sheet().doWrite(list);
    }

    public static void main(String[] args){
        write();
    }
}

 

****************

使用测试

 

                        

 

 

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值