easyExceal读excel
作者:互联网
首先引入
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>1.1.2-beta4</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
//获取excle
public List<LoanInfo> getQuesSource(InputStream inputStream, Class<? extends BaseRowModel> className) {
List<LoanInfo> loanInfoList = new ArrayList<>();
List<Object> list = EasyExcelFactory.read(inputStream, new Sheet(6, 1, className));
list.stream().forEach(o -> {
LoanInfo loanInfo = (LoanInfo) o;
loanInfoList.add(loanInfo);
});
return loanInfoList;
Sheet 第一个参数 sheet页
第二个参数 从第几行开始读
第三个参数 模型.class
//模型类
@Data
public class LoanInfo extends BaseRowModel {
@ExcelProperty(index = 0,value = "disease_value")
private String diseaseValue;
@ExcelProperty(index = 1,value = "disease_detail_code")
private String diseaseDetailCode;
@ExcelProperty(index = 2,value = "disease_detail_value")
private String diseaseDetailValue;
@ExcelProperty(index = 3,value = "user_flag")
private String userFlag;
@ExcelProperty(index = 4,value = "question1_code")
private String question1Code;
@ExcelProperty(index = 5,value = "question1_value")
private String question1Value;
@ExcelProperty(index = 6,value = "answer1_code")
private String answer1Code;
@ExcelProperty(index = 7,value = "question2_code")
private String question2Code;
@ExcelProperty(index = 8,value = "question2_value")
private String question2Value;
@ExcelProperty(index = 9,value = "answer2_code")
private String answer2Code;
@ExcelProperty(index = 10,value = "question3_code")
private String question3Code;
@ExcelProperty(index = 11,value = "question3_value")
private String question3Value;
@ExcelProperty(index = 12,value = "answer3_code")
private String answer3Code;
@ExcelProperty(index = 13,value = "uw_code")
private String uwCode;
@ExcelProperty(index = 14,value = "uw_append")
private String uwAppend;
@ExcelProperty(index = 15,value = "uw_value")
private String uwValue;
@Override
public String toString() {
return "LoanInfo{" +
"diseaseValue='" + diseaseValue + '\'' +
", diseaseDetailCode='" + diseaseDetailCode + '\'' +
", diseaseDetailValue='" + diseaseDetailValue + '\'' +
", userFlag='" + userFlag + '\'' +
", question1Code='" + question1Code + '\'' +
", question1Value='" + question1Value + '\'' +
", answer1Code='" + answer1Code + '\'' +
", question2Code='" + question2Code + '\'' +
", question2Value='" + question2Value + '\'' +
", answer2Code='" + answer2Code + '\'' +
", question3Code='" + question3Code + '\'' +
", question3Value='" + question3Value + '\'' +
", answer3Code='" + answer3Code + '\'' +
", uwCode='" + uwCode + '\'' +
", uwAppend='" + uwAppend + '\'' +
", uwValue='" + uwValue + '\'' +
'}';
}
}
标签:index,code,String,excel,ExcelProperty,easyExceal,private,value 来源: https://www.cnblogs.com/yushizhang/p/13045696.html