<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
package com.yl.jasperreportdemo.domain;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import java.io.Serializable;
import java.util.Date;
@ExcelTarget("student")
public class Student implements Serializable {
@Excel(name = "name")
private String name;
@Excel(name = "age")
private int age;
@Excel(name = "sex",replace = { "男_0", "女_1",})
private int sex;
@Excel(name = "date",format = "yyyy-MM-dd")
private Date birthDay;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public Date getBirthDay() {
return birthDay;
}
public void setBirthDay(Date birthDay) {
this.birthDay = birthDay;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", sex=" + sex +
", birthDay=" + birthDay +
'}';
}
}
package com.yl.jasperreportdemo.controller;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.yl.jasperreportdemo.domain.Student;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.util.List;
public class ImportController {
public static void main(String[] args) {
ImportParams params = new ImportParams();
//表格标题行数,默认0
params.setTitleRows(0);
//表头行数,默认1
params.setHeadRows(1);
List<Student> list = ExcelImportUtil.importExcel(
new File("F:/test1.xlsx"),
Student.class, params);
System.out.println(list.size());
if (!CollectionUtils.isEmpty(list)) {
list.stream().forEach(item -> {
System.out.println(item);
});
}
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_41359273/article/details/122369282
内容来源于网络,如有侵权,请联系作者删除!