效果
![在这里插入图片描述](https://img-blog.csdnimg.cn/f1eda292d7934bd9921c9a9cae368411.png)
代码
@ApiOperation("多sheet导入")
@PostMapping(value = "/import", headers = "content-type=mutipart/form-data", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void importSheet(@RequestParam("file") MultipartFile file) throws Exception {
ImportParams importSheet1Params = new ImportParams();
importSheet1Params.setStartSheetIndex(0);
List<ExcelDTO1> sheet1Data = ExcelImportUtil.importExcel(file.getInputStream(), ExcelDTO1.class, importSheet1Params);
log.info("sheet1 data size is {}",sheet1Data.size());
ImportParams import2Sheet2Params = new ImportParams();
import2Sheet2Params.setStartSheetIndex(1);
List<ExcelDTO1> sheet2Data = ExcelImportUtil.importExcel(file.getInputStream(), ExcelDTO2.class, import2Sheet2Params);
log.info("sheet2 data size is {}",sheet2Data.size());
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/6bba9b5b79844c769bccd4902262adae.png)
@Data
public class ExcelDTO1{
@Excel(name = "列表1",orderNum = "1")
private String name;
@Excel(name = "列表2",orderNum = "1")
private String level;
}
@Data
public class ExcelDTO2{
@Excel(name = "字段1",orderNum = "1")
private String name;
@Excel(name = "字段2",orderNum = "2")
private String level;
@Excel(name = "字段3",orderNum = "3")
private String aaaa;
}