EasyExcel对表格的读取转化list集合

package com.codvision.gms.easyExcel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.codvision.gms.easyExcel.bean.ExcelData;

import java.util.*;

/**
 * excel的读取 返回list集合
 * @author dbb
 * @date 2022-06-14
 */
public class EasyExcelRead {
    public static void main(String[] args) {
        final List<ExcelData> list = new LinkedList<>();
        EasyExcel.read("C:\\Users\\dongbobo\\Desktop\\开发区人员名单.xls")
                .head(ExcelData.class)
                .sheet().registerReadListener(new AnalysisEventListener<ExcelData>() {

            @Override
            public void invoke(ExcelData excelData, AnalysisContext analysisContext) {
                list.add(excelData);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                System.out.println("数据读取完毕");
            }
        }).doRead();
        for (ExcelData excelData : list) {
            System.out.println("--->" + excelData);
        }
    }
}

你可能感兴趣的:(java,开发语言)