1、引入依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</version>
</dependency>
2、ExcelUtil
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.ReadListener;
import java.util.List;
public class ExcelUtil {
public static void readToListener(String excelPath, Class<?> clazz, ReadListener readListener){
EasyExcel.read(excelPath, clazz, readListener).sheet().doRead();
}
public static void write(String excelPath, Class<?> clazz, List<?> data,String sheetName){
EasyExcel.write(excelPath, clazz).sheet(sheetName).doWrite(data);
}
public static void writeDynamicHead(String excelPath,List<List<String>> head,String sheetName,List<List<String>> data) {
EasyExcel.write(excelPath).head(head).sheet(sheetName).doWrite(data);
}
}