springboot集成
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
导入对应实体类
public class DataImport {
@Excel(name = "序号")
private String sno;
@Excel(name = "姓名")
private String name;
//省略set get
}
示例
@PostMapping("/importData")
public void importData(@RequestPart("file") MultipartFile file) throws Exception {
InputStream inputStream = file.getInputStream();
//导入参数配置
ImportParams importParams=new ImportParams();
//表格标题行数,默认0
importParams.setTitleRows(2);
//表头行数,默认1
importParams.setHeadRows(1);
//开始读取的sheet位置,默认为0
importParams.setStartSheetIndex(1);
List<DataImport> list = ExcelImportUtil.importExcel(inputStream, DataImport.class, importParams);
}
excel
![](https://i-blog.csdnimg.cn/blog_migrate/27f21dc299a82a4eff79bcb2a2c04790.jpeg)
参考地址
EasyPoi教程_V1.0
1.1 介绍 - Powered by MinDoc