读Excel
1、依赖包
com.alibaba
easyexcel
2.0.5
2、代码import java.io.File;
import com.alibaba.excel.EasyExcel;
public class Demo7 {
public static void main(String[] args) {
String fileName = "D:" + File.separator + "001.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
EasyExcel.read(fileName, User.class, new UserListener()).sheet().doRead();
//EasyExcel.read(InputStream in, User.class, new UserListener()).sheet().doRead();
}
}
3、实体类import java.util.Date;
import com.alibaba.excel.annotation.ExcelProperty;
/**
*/
/**
* @author Martin
* @Date 2019年11月1日 下午11:36:58
* @Desc
*/
public class User {
/**
* value-->表头 index-->列(从0开始)
*/
@ExcelProperty(index = 0)
private String uid;
@ExcelProperty(index = 1, value = "姓名")
private String name;
@ExcelProperty(index = 2)
private Integer age;
@ExcelProperty(index = 3)
private String address;
// converter 格式转换类
@ExcelProperty(index = 4, converter = DateStringConverter.class)
private Date birthday;
public User() {
}
public User(String uid, String name, Integer age, String address) {
this.uid = uid;
this.name = name;
this.age = age;
this.addr