准备工作:
springboot项目
maven
1.导入依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>1.1.1</version>
</dependency>
2.建立Java实体ExcelModel类
package com.itycl.exceldemo.tets;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import lombok.Data;
import java.io.Serializable;
@SuppressWarnings("serial")
@Data
public class ExcelModel extends BaseRowModel implements Serializable {
@ExcelProperty(value = "指标ID" ,index = 0)
private String id;
@ExcelProperty(value = "指标名称",index = 1)
private String name;
@ExcelProperty(value = "指标功能集",index = 2)
private String collection1;
@ExcelProperty(value = "计算公式",index = 3)
private String shhe;
}
3.EasyExcelUtils工具类
package com.itycl.exceldemo.tets;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.BaseRowModel;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.metadata.Table;
import com.alibaba.excel.support.ExcelTypeEnum;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
public class EasyExcelUtil {
private static class StringExcelListener extends AnalysisEventListener {