註解實現阿里Easy Excel自定義樣式設置

基於alibaba/easyexcel進行樣式擴展封裝而來的,增加了一些樣式註解

可以解決什麼問題

  1. 註解式樣式
  2. 代碼自定義單元格樣式處理鏈 -> addCustomCellStyleHandler
  3. 凍結行列樣式
  4. 合併單元格樣式
  5. 設置內容下拉框
  6. 背景顏色
  7. 字體設置
  8. 列寬度設置
  9. 邊框樣式
  10. 居中方式
  11. 是否換行

效果

在這裏插入圖片描述
在這裏插入圖片描述

DEMO

model代碼示例


@CellFreeze(freezeRow = 2, freezeCol = 2)
// 寬度默認值
@ColumnWidth(width = 40)
// 同時作用於表標題和內容的樣式默認值
@CellStyle(fontStyle = @FontStyle(color = IndexedColors.LIGHT_BLUE, size = 14))
public class MyModel1 extends BaseRowModel {

    // easyexcel 解析註解
    @ExcelProperty(value={"pri", "pr1"}, index = 0)
    private String pr1;

    @ExcelProperty(value={"pri", "pr2"}, index = 1)
    private String pr2;

    @ExcelProperty(value = {"propValue1"}, index = 2)
    // 數組方式指定的下拉框約束
    @ExplicitConstraint(source = {"aaa1", "aaa2", "aaa3"})
    @ColumnWidth(width = 100)
    private String propValue1;

    @ExcelProperty(value = {"propValue2"}, index = 3)
    @ExplicitConstraint(enumSource = MyConstraintEnum.class)
    private String propValue2;

    @ExcelProperty(value = {"score"}, index = 4)
    @ColumnWidth(width = 50)
    private Integer score;

    @ExcelProperty(value = {"date"}, index = 5, format = "yyyy-MM-dd HH:mm:ss")
    private Date date;

    public String getPr1() {
        return pr1;
    }

    public void setPr1(String pr1) {
        this.pr1 = pr1;
    }

    public String getPr2() {
        return pr2;
    }

    public void setPr2(String pr2) {
        this.pr2 = pr2;
    }

    public String getPropValue1() {
        return propValue1;
    }

    public void setPropValue1(String propValue1) {
        this.propValue1 = propValue1;
    }

    public String getPropValue2() {
        return propValue2;
    }

    public void setPropValue2(String propValue2) {
        this.propValue2 = propValue2;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}

詳細調用代碼戳下方鏈接

有標題頭demo

無標題頭demo1

無標題頭demo2

引用

<dependency>
    <groupId>com.uetty</groupId>
    <artifactId>common-excel</artifactId>
    <version>1.0.3</version>
</dependency>

源碼

GITHUB倉庫鏈接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章