我是靠谱客的博主 羞涩月光,这篇文章主要介绍alibaba EasyExcel 属性注解,现在分享给大家,希望可以做个参考。

常用注解详解:

注解名称作用范围属性默认值描述
@ColumnWidth类或属性value(int)-1设置表格的列宽
@ContentRowHeightvalue(int)-1设置表格的高度(不含表头)
@HeadRowHeightvalue(int)-1设置表格表头的高度
@HeadFontStyle类或属性fontName(String)宋体设置表格表头的字体
fontHeightInPoints(short)14设置表格表头字体的大小
@ExcelIgnore属性转化表格时忽略该字段
@ExcelIgnoreUnannotated转化表格时忽略所有未注释的字段
@ExcelProperty属性value(String[]){""}说明属性对应表头的名称
index(int)-1说明属性在表格的位置
converter(Class<? extends Converter>)AutoConverter.class自定义转换类
@DateTimeFormat属性value(String)""设置转化格式
use1904windowing(boolean)false是否使用1904年日期系统

@NumberFormat还不清楚,待补充

注释:

1. 是否使用1904年日期系统

Excel 支持两个日期系统:1900年日期系统(推荐)和 1904年日期系统。每个日期系统使用日期作为计算的所有其他工作簿中的唯一开始日期。所有版本的 Excel for Windows 都计算基于 1900年日期系统中的日期。Excel 2008 for Mac 和早期 Excel for Mac 版本计算基于 1904年日期系统的日期。Excel 2016 for Mac 和 Excel for Mac 2011 使用 1900年日期系统,保证日期与 Excel for Windows 的兼容性

2. 自定义格式转换

Excel转换类

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Data public class ConverterData { /** * converter属性定义自己的字符串转换器 */ @ExcelProperty(converter = CustomStringConverter.class) private String string; /** * 这里用string 去接日期才能格式化 */ @DateTimeFormat("yyyy年MM月dd日 HH时mm分ss秒") private String date; /** * 我想接收百分比的数字 */ @NumberFormat("#.##%") private String doubleData; }

自定义的转换器

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import com.alibaba.excel.converters.Converter; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; import com.alibaba.excel.metadata.property.ExcelContentProperty; public class CustomStringConverter implements Converter<String> { /** * java中的数据格式 */ @Override public Class supportJavaTypeKey() { return String.class; } /** * Excel中的数据格式 */ @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.STRING; } /** * 这里读的时候会调用 */ @Override public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { return "自定义的字符:" + cellData.getStringValue(); } /** * 这里是写的时候会调用 */ @Override public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { return new CellData("自定义的字符:" + value); } }
3. 复杂头写入(合并单元格)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/** * 主标题 将整合为一个单元格效果如下: * ————————————————————————— * | 主标题 | * ————————————————————————— * |字符串标题|日期标题|数字标题| * ————————————————————————— */ @ExcelProperty({"主标题", "字符串标题"}) private String string; @ExcelProperty({"主标题", "日期标题"}) private Date date; @ExcelProperty({"主标题", "数字标题"}) private Double doubleData;

最后

以上就是羞涩月光最近收集整理的关于alibaba EasyExcel 属性注解的全部内容,更多相关alibaba内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部