Search in sources :

Example 1 with MapExcelImporter

use of com.qiuyj.excel.importer.MapExcelImporter in project qiuyj-code by qiuyuanjun.

the class ExcelOpsFactory method getExcelImporter.

@SuppressWarnings("unchecked")
public static ExcelImporter getExcelImporter(InputStream in, Class<?> beanCls) {
    Objects.requireNonNull(in);
    Workbook wb;
    try {
        wb = WorkbookFactory.create(in);
    } catch (InvalidFormatException | IOException e) {
        // 关闭流
        StreamUtils.closeQuietly(in);
        throw new IllegalStateException("Error parsing excel file.\n Caused by: " + e, e);
    }
    if (Objects.isNull(beanCls)) {
        return new MapExcelImporter(wb);
    } else {
        return new BeanExcelImporter(wb, beanCls);
    }
}
Also used : MapExcelImporter(com.qiuyj.excel.importer.MapExcelImporter) IOException(java.io.IOException) BeanExcelImporter(com.qiuyj.excel.importer.BeanExcelImporter) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) Workbook(org.apache.poi.ss.usermodel.Workbook)

Aggregations

BeanExcelImporter (com.qiuyj.excel.importer.BeanExcelImporter)1 MapExcelImporter (com.qiuyj.excel.importer.MapExcelImporter)1 IOException (java.io.IOException)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1