easyexcel 合并单元格

x33g5p2x  于2021-12-28 转载在 其他  
字(1.1k)|赞(0)|评价(0)|浏览(1546)

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

使用测试

                      

相关文章