欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

easyexcel 合并单元格

程序员文章站 2022-03-10 18:20:08
easyexcel合并单元格...

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();
    }
}

 

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

使用测试

 

                        easyexcel 合并单元格

 

 

本文地址:https://blog.csdn.net/weixin_43931625/article/details/107585082

相关标签: easyexcel