当前位置: 移动技术网 > IT编程>软件设计>面向对象 > easyexcel 合并单元格

easyexcel 合并单元格

2020年07月27日  | 移动技术网IT编程  | 我要评论

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

 

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

使用测试

 

                        

 

 

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网