pom文件:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</version>
</dependency>
实体类
public class DrugExcelChangeDTO {
//sku
/**
* 69码/条形码(选填)
*/
@ExcelProperty(index = 0)
private String barcode;
//spu
/**
* 通用名
*/
@ExcelProperty(index = 1)
private String name;
//spu
/**
* 规格
*/
@ExcelProperty(index = 2)
private String spec;
//sku
/**
* 生产厂家(选填)
*/
@ExcelProperty(index = 3)
private String enterprise;
//sku
/**
* 国药准字/批准文号(选填)
*/
@ExcelProperty(index = 4)
private String approvalNumber;
//spu
/**
* 包装单位(请下拉选择内容,如片、盒、瓶、袋、粒、包等)
*/
@ExcelProperty(index = 5)
private String unit;
//spu
/**
* 使用频次(选填,请下拉选择内容,如2次/天、2次/周)
*/
@ExcelProperty(index = 7)
private String usageFrequencyName;
//spu
/**
* 每次用量(选填,请填写数字)
*/
@ExcelProperty(index = 8)
private String perNum;
//spu
/**
* 用量单位(选填,请下拉选择内容,如盒、瓶、袋、粒、包、g、mg等))
*/
@ExcelProperty(index = 9)
private String perUnit;
//spu
/**
* 用药天数(请规范填写,范围1-120)
*/
@ExcelProperty(index = 10)
private Integer takingDay;
@ExcelProperty(index = 11)
private String errorMassage;
public static void main(String[] args) {
String fileName="D:/公司库导入模板 (1).xlsx";
InputStream inputStream=null;
try {
inputStream = new FileInputStream(fileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
List<DrugExcelChangeDTO> list= EasyExcel.read(inputStream)
.head(DrugExcelChangeDTO.class)
// 设置sheet,默认读取第一个
.sheet()
// 设置标题所在行数
.headRowNumber(1)
.doReadSync();
System.out.println(list.size());
for (DrugExcelChangeDTO drugExcelChangeDTO:list) {
System.out.println(drugExcelChangeDTO);
}
}
}