Search in sources :

Example 1 with ModelExcelListener

use of cn.ruiyeclub.listener.ModelExcelListener in project SpringBoot-Hello by ruiyeclub.

the class ExcelUtil method readExcel.

/**
 * @param inputStream   Excel的输入流
 * @param clazz         模型的类
 * @param excelTypeEnum Excel的格式(XLS或XLSX)
 * @Description: 使用模型来读取Excel
 * @Date: 2020/1/16 21:41
 * @Return: java.util.List<E>
 * @Throws: Exception
 */
public static <E> List<E> readExcel(InputStream inputStream, Class<? extends BaseRowModel> clazz, ExcelTypeEnum excelTypeEnum) throws Exception {
    // 解析每行结果在listener中处理
    ModelExcelListener<E> listener = new ModelExcelListener<E>();
    ExcelReader excelReader = new ExcelReader(inputStream, excelTypeEnum, null, listener);
    // 默认只有一列表头
    excelReader.read(new Sheet(1, 1, clazz));
    return listener.getDataList();
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ModelExcelListener(cn.ruiyeclub.listener.ModelExcelListener) Sheet(com.alibaba.excel.metadata.Sheet)

Aggregations

ModelExcelListener (cn.ruiyeclub.listener.ModelExcelListener)1 ExcelReader (com.alibaba.excel.ExcelReader)1 Sheet (com.alibaba.excel.metadata.Sheet)1