easyexcel
easyexcel copied to clipboard
excel-read-日期-to-LocalDateTime
EasyExcel 读取excel, 日期格式的列,
java里面定义的 实体类, 对应的格式是 LocalDateTime
User { LocalDataTime ctime }
触发Bug的代码
String path = "/Users/daniellu/Desktop/eladmin_user.xlsx";
final List<User> userList = EasyExcel.read(path).sheet(0).head(User.class).doReadSync();
System.out.println(userList);
@Data
public class User {
/** ID */
@ExcelProperty(index = 0)
private Integer id;
/** 姓名 */
@ExcelProperty(index = 1)
private String name;
/** 性别 */
@ExcelProperty(index = 2)
private String sex;
// @ExcelProperty(index = 3)
// private LocalDate birth;
@ExcelProperty(index = 4)
private String nation;
/** 身份证号 */
@ExcelProperty(index = 5)
private String idNumber;
/** 密码 */
@ExcelProperty(index = 6)
private String password;
/** 最近登陆时间 */
@ExcelProperty(index = 7)
private Integer lastLoginTime;
@ExcelProperty(index = 9)
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
private LocalDateTime ctime;
/** 报名step */
@ExcelProperty(index = 10)
private Integer enrollStep;
@ExcelProperty(index = 11)
private Integer studentInfoId;
}
提示的异常或者没有达到的效果 Caused by: com.alibaba.excel.exception.ExcelDataConvertException: Converter not found, convert STRING to java.time.LocalDateTime at com.alibaba.excel.util.ConverterUtils.doConvertToJavaObject(ConverterUtils.java:130)
建议支持 jdk8 日期格式, 现在jdk8 已经普及了啊
尝试升级一下版本。我用最新版本转换为localdatetime没问题
新版本已经支持了 建议使用最新版本
非常感谢大家的帮助, 我试一下
升级到 3. 2.1 , 可以了, 感谢大家!!!