11個注解
-
@ExcelProperty
-
@ColumnWith 列寬
-
@ContentFontStyle 文本字體樣式
-
@ContentLoopMerge 文本合並
-
@ContentRowHeight 文本行高度
-
@ContentStyle 文本樣式
-
@HeadFontStyle 標題字體樣式
-
@HeadRowHeight 標題高度
-
@HeadStyle 標題樣式
-
@ExcelIgnore 忽略項
-
@ExcelIgnoreUnannotated 忽略未注解
字段注解 | 類注解 |
---|---|
@ColumnWith(列寬) | @ColumnWidth(全局列寬) |
@ExcelProperty(字段配置) | @HeadFontStyle(頭樣式) |
@HeadRowHeight(標題高度) | |
@ContentFontStyle(內容字體樣式) | |
@ContentRowHeight(內容高度) |
@ExcelProperty
必要的一個注解,注解中有三個參數value
,index
,converter
分別代表列明,列序號,數據轉換方式
value
和index
只能二選一,通常不用設置converter
1.value 通過標題文本對應
2.index 通過文本行號對應
3.converter 轉換器,通常入庫和出庫轉換使用,如性別入庫0和1,出庫男和女
最佳實踐
public class ImeiEncrypt {
@ExcelProperty(value = "值")
private String valueField;
@ExcelProperty(value = 1,converter =IndustryIdConverter.class)
private String indexField;
@ExcelProperty(value = "值對應和轉換器",converter =IndustryIdConverter.class)
private String valueAndConverterField;
}
@ColumnWith
設置列寬度,只有一個參數value,value的單位是字符長度,最大可以設置255個字符,因為一個excel單元格最大可以寫入的字符個數就是255個字符。
最佳實踐
public class ImeiEncrypt {
@ColumnWidth(value = 18)
private String imei;
}
@ContentFontStyle
用於設置單元格內容字體格式的注解
參數:
參數 | 含義 |
---|---|
fontName | 字體名稱 |
fontHeightInPoints | 字體高度 |
italic | 是否斜體 |
strikeout | 是否設置刪除水平線 |
color | 字體顏色 |
typeOffset | 偏移量 |
underline | 下划線 |
bold | 是否加粗 |
charset | 編碼格式 |
@ContentLoopMerge
用於設置合並單元格的注解
參數:
參數 | 含義 |
---|---|
eachRow | |
columnExtend |
@ContentRowHeight
用於設置行高
參數:
參數 | 含義 |
---|---|
value | 行高,-1 代表自動行高 |
@ContentStyle
設置內容格式注解
參數:
參數 | 含義 |
---|---|
dataFormat | 日期格式 |
hidden | 設置單元格使用此樣式隱藏 |
locked | 設置單元格使用此樣式鎖定 |
quotePrefix | 在單元格前面增加`符號,數字或公式將以字符串形式展示 |
horizontalAlignment | 設置是否水平居中 |
wrapped | 設置文本是否應換行。將此標志設置為true 通過在多行上顯示使單元格中的所有內容可見 |
verticalAlignment | 設置是否垂直居中 |
rotation | 設置單元格中文本旋轉角度。03版本的Excel旋轉角度區間為-90°90°,07版本的Excel旋轉角度區間為0°180° |
indent | 設置單元格中縮進文本的空格數 |
borderLeft | 設置左邊框的樣式 |
borderRight | 設置右邊框樣式 |
borderTop | 設置上邊框樣式 |
borderBottom | 設置下邊框樣式 |
leftBorderColor | 設置左邊框顏色 |
rightBorderColor | 設置右邊框顏色 |
topBorderColor | 設置上邊框顏色 |
bottomBorderColor | 設置下邊框顏色 |
fillPatternType | 設置填充類型 |
fillBackgroundColor | 設置背景色 |
fillForegroundColor | 設置前景色 |
shrinkToFit | 設置自動單元格自動大小 |
@HeadFontStyle
用於定制標題字體格式
參數 | 含義 |
---|---|
fontName | 設置字體名稱 |
fontHeightInPoints | 設置字體高度 |
italic | 設置字體是否斜體 |
strikeout | 是否設置刪除線 |
color | 設置字體顏色 |
typeOffset | 設置偏移量 |
underline | 設置下划線 |
charset | 設置字體編碼 |
bold | 設置字體是否加粗 |
@HeadRowHeight
設置標題行行高
參數 | 含義 |
---|---|
value | 設置行高,-1代表自動行高 |
@HeadStyle
設置標題樣式
參數 | 含義 |
---|---|
dataFormat | 日期格式 |
hidden | 設置單元格使用此樣式隱藏 |
locked | 設置單元格使用此樣式鎖定 |
quotePrefix | 在單元格前面增加`符號,數字或公式將以字符串形式展示 |
horizontalAlignment | 設置是否水平居中 |
wrapped | 設置文本是否應換行。將此標志設置為true 通過在多行上顯示使單元格中的所有內容可見 |
verticalAlignment | 設置是否垂直居中 |
rotation | 設置單元格中文本旋轉角度。03版本的Excel旋轉角度區間為-90°90°,07版本的Excel旋轉角度區間為0°180° |
indent | 設置單元格中縮進文本的空格數 |
borderLeft | 設置左邊框的樣式 |
borderRight | 設置右邊框樣式 |
borderTop | 設置上邊框樣式 |
borderBottom | 設置下邊框樣式 |
leftBorderColor | 設置左邊框顏色 |
rightBorderColor | 設置右邊框顏色 |
topBorderColor | 設置上邊框顏色 |
bottomBorderColor | 設置下邊框顏色 |
fillPatternType | 設置填充類型 |
fillBackgroundColor | 設置背景色 |
fillForegroundColor | 設置前景色 |
shrinkToFit | 設置自動單元格自動大小 |
@ExcelIgnore
不將該字段轉換成Excel
@ExcelIgnoreUnannotated
沒有注解的字段都不轉換