实现Excel导入导出工具基于阿里出品的EasyExcel封装(第一篇)

实现Excel导入导出工具基于阿里出品的EasyExcel封装(第一篇)

Excel准备

1. 以Notice模块为例,基于官方文档,我们编写一个EasyExcel格式的bean

@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class NoticeExcel {
   

	@ColumnWidth(15)
	@ExcelProperty("标题")
	private String title;
	@ExcelIgnore
	@ColumnWidth(10)
	@ExcelProperty("类型")
	private Integer category;
	@ColumnWidth(20)
	@ExcelProperty("类型名称")
	private String categoryName;
	@ColumnWidth(10)
	@ExcelProperty("发布日期")
	private Date releaseTime;
	@ColumnWidth(30)
	@ExcelProperty("内容")
	private String content;
}

2. 针对EasyExcel,写一个轻量级的工具类ExcelUtil,具体代码如下,大家可以在阅读完官方文档后再阅读封装源码

/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.core.excel.util;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.DateUtils;
import lombok
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值