使用easypoi 导入excel
一、pom文件
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.0.3</version>
</dependency>
二、创建pojo类
public class InstallationUser {
@Excel(name = “姓名”,orderNum = “0”)
private String name;
@Excel(name = “年龄”,orderNum = “1”)
private String age;
@Excel(name = “性别”,orderNum = “2” ,replace={“男_0”,“女_1”})
private String sex;
三、测试
@Test
public void test(){
ImportParams params = new ImportParams();
params.setStartSheetIndex(1);//第几个sheet从0开始
params.setTitleRows(0);//表格标题行数,默认0
params.setHeadRows(1);//表头行数,默认1
long start = new Date().getTime();
List<InstallationUser> list = ExcelImportUtil.importExcel(
new File("C:\\Users\\Administrator\\Desktop\\sheet\\安装批量导入.xlsx"),
InstallationUser.class, params);
System.out.println(new Date().getTime() - start);
System.out.println(list.size());
for (InstallationUser installationUser : list) {
System.out.println(installationUser);
}
System.out.println(ReflectionToStringBuilder.toString(list));
}