1.maven坐标
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.1.0</version>
</dependency>
2.代码
/**
* excel批量导入
* @param file
* @return
*/
@PostMapping("/excel")
public String importExcel(@RequestParam("file") MultipartFile file) throws Exception
{
ImportParams importParams = new ImportParams();
importParams.setTitleRows(1);
importParams.setHeadRows(1);
ExcelImportResult<Student> result = ExcelImportUtil.importExcelMore(file.getInputStream(), Student.class, importParams);
List<Student> studentExportList = result.getList();
studentExportList.forEach(student -> System.err.println(student));
//下面进行数据库保存数据,处理自己公司相应业务
return "ok";
}
@Data
public class Student
{
@Excel(name = "姓名", orderNum = "1", width = 18)
private String name;
@Excel(name = "年龄", orderNum = "2", width = 18)
private int age;
@Excel(name = "性别", orderNum = "3", width = 18)
private String sex;
}
3.准备表格数据
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/459eb0f47107fdcf6b995f1cad65b720.png)
4.调用接口结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0bcdde287fad8e00cdd53ceded59accc.png)