1.导入依赖
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.1.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>4.1.0</version>
</dependency>
2.设置实体类:
/**
* 校准台账id
*/
@TableId
private Long jiaoId;
/**
* 器具编号
*/
@Excel(name = "器具编号")
private String jiaoNumber;
/**
* 名称
*/
@Excel(name = "名称")
private String jiaoName;
/**
* 出厂编号
*/
@Excel(name = "出厂编号")
private String jiaoFactoryNumber;
/**
* 规格型号
*/
@Excel(name = "规格型号")
private String jiaoModelNumber;
/**
* 量程
*/
@Excel(name = "量程")
private String jiaoRange;
/**
* 安装位置
*/
@Excel(name = "安装位置")
private String jiaoSetSite;
/**
* 用途
*/
@Excel(name = "用途")
private String jiaoUse;
/**
* 生产厂家
*/
@Excel(name = "生产厂家")
private String jiaoManufacturer;
/**
* 检测结果
*/
@Excel(name = "检测结果")
private String jiaoTestResult;
/**
* 检测到期时间
*/
@Excel(name = "检定到期时间")
private String jiaoTestExpirationTime;
/**
* 管理类别
*/
@Excel(name = "管理类别")
private String jiaoManagement;
/**
* 备注
*/
@Excel(name = "备注")
private String remake;
确保name属性跟表头一致
3.controller代码
/**
* 上传文件
* @param multipartFile
* @return
* @throws Exception
*/
@RequestMapping("/upload")
public R UploadFile(@RequestParam(value = "file",required = false) MultipartFile multipartFile) throws Exception {
ImportParams params = new ImportParams();
//设置标题占行
params.setTitleRows(3);
//设置表头占行
params.setHeadRows(1);
//解决空行问题 选择一个不为空的列
params.setKeyIndex(1);
//sheet位置 从0开始
params.setStartSheetIndex(0);
List<SysCalibrateEntity> list = ExcelImportUtil.importExcel(multipartFile.getInputStream(),
SysCalibrateEntity.class, params);
return R.ok().put("data",list);
}
标题占行和表头占行必须要设置正确