Search in sources :

Example 1 with ExcelReaderBuilder

use of com.alibaba.excel.read.builder.ExcelReaderBuilder in project easyexcel by alibaba.

the class EasyExcelFactory method read.

/**
 * Build excel the read
 *
 * @param inputStream
 *            Input stream to read.
 * @param head
 *            Annotate the class for configuration information.
 * @param readListener
 *            Read listener.
 * @return Excel reader builder.
 */
public static ExcelReaderBuilder read(InputStream inputStream, Class head, ReadListener readListener) {
    ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
    excelReaderBuilder.file(inputStream);
    if (head != null) {
        excelReaderBuilder.head(head);
    }
    if (readListener != null) {
        excelReaderBuilder.registerReadListener(readListener);
    }
    return excelReaderBuilder;
}
Also used : ExcelReaderBuilder(com.alibaba.excel.read.builder.ExcelReaderBuilder)

Example 2 with ExcelReaderBuilder

use of com.alibaba.excel.read.builder.ExcelReaderBuilder in project easyexcel by alibaba.

the class EasyExcelFactory method read.

/**
 * Build excel the read
 *
 * @param pathName
 *            File path to read.
 * @param head
 *            Annotate the class for configuration information.
 * @param readListener
 *            Read listener.
 * @return Excel reader builder.
 */
public static ExcelReaderBuilder read(String pathName, Class head, ReadListener readListener) {
    ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
    excelReaderBuilder.file(pathName);
    if (head != null) {
        excelReaderBuilder.head(head);
    }
    if (readListener != null) {
        excelReaderBuilder.registerReadListener(readListener);
    }
    return excelReaderBuilder;
}
Also used : ExcelReaderBuilder(com.alibaba.excel.read.builder.ExcelReaderBuilder)

Example 3 with ExcelReaderBuilder

use of com.alibaba.excel.read.builder.ExcelReaderBuilder in project kapcb-common by kapbc.

the class AnalyzeUtil method analyzeExcel.

/**
 * analyze excel
 *
 * @param docPath         String
 * @param headRowNumber   Integer
 * @param modelClazz      Class<? extends M>
 * @param analyzeListener T
 * @param <M>             <M>
 * @param <T>             <T>
 * @return T
 */
public static <M, T extends AnalysisEventListener<M>> T analyzeExcel(String docPath, Integer headRowNumber, Class<? extends M> modelClazz, T analyzeListener) {
    if (StringUtils.isBlank(docPath)) {
        throw new IllegalArgumentException("analyze excel param error, the doc path is : {}" + docPath);
    }
    String fileName = FileUtil.getPath() + docPath;
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(fileName);
    } catch (FileNotFoundException e) {
        log.error("analyze excel get io stream error, error message is : {}", e.getMessage());
    }
    ExcelReaderBuilder read = EasyExcelFactory.read(inputStream, modelClazz, analyzeListener);
    if (Objects.nonNull(headRowNumber)) {
        read.headRowNumber(headRowNumber);
    }
    ExcelReader build = read.build();
    build.readAll();
    build.finish();
    return analyzeListener;
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ExcelReaderBuilder(com.alibaba.excel.read.builder.ExcelReaderBuilder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream)

Example 4 with ExcelReaderBuilder

use of com.alibaba.excel.read.builder.ExcelReaderBuilder in project easyexcel by alibaba.

the class EasyExcelFactory method read.

/**
 * Build excel the read
 *
 * @param file
 *            File to read.
 * @param head
 *            Annotate the class for configuration information.
 * @param readListener
 *            Read listener.
 * @return Excel reader builder.
 */
public static ExcelReaderBuilder read(File file, Class head, ReadListener readListener) {
    ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
    excelReaderBuilder.file(file);
    if (head != null) {
        excelReaderBuilder.head(head);
    }
    if (readListener != null) {
        excelReaderBuilder.registerReadListener(readListener);
    }
    return excelReaderBuilder;
}
Also used : ExcelReaderBuilder(com.alibaba.excel.read.builder.ExcelReaderBuilder)

Example 5 with ExcelReaderBuilder

use of com.alibaba.excel.read.builder.ExcelReaderBuilder in project chunjun by DTStack.

the class ExcelFileReadClient method open.

@Override
public void open(InputStream inputStream, FtpConfig ftpConfig) throws IOException {
    cellCount = ftpConfig.getColumn().size();
    ExcelReadListener listener = new ExcelReadListener();
    queue = listener.getQueue();
    ExcelReaderBuilder builder = EasyExcel.read(inputStream, listener);
    if (!ftpConfig.getIsFirstLineHeader()) {
        builder.headRowNumber(0);
    }
    builder.ignoreEmptyRow(true);
    ExcelReader reader = builder.build();
    sheetNum = reader.excelExecutor().sheetList().size();
    executorService = new ThreadPoolExecutor(1, 1, 0, NANOSECONDS, new LinkedBlockingDeque<>(2), new BasicThreadFactory.Builder().namingPattern("excel-schedule-pool-%d").uncaughtExceptionHandler(new ExcelReaderExceptionHandler()).daemon(false).build());
    ExcelReaderExecutor executor = new ExcelReaderExecutor(reader);
    executorService.execute(executor);
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ExcelReadListener(com.dtstack.flinkx.connector.ftp.client.excel.ExcelReadListener) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ExcelReaderBuilder(com.alibaba.excel.read.builder.ExcelReaderBuilder) ExcelReaderBuilder(com.alibaba.excel.read.builder.ExcelReaderBuilder) ExcelReaderExceptionHandler(com.dtstack.flinkx.connector.ftp.client.excel.ExcelReaderExceptionHandler) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ExcelReaderExecutor(com.dtstack.flinkx.connector.ftp.client.excel.ExcelReaderExecutor)

Aggregations

ExcelReaderBuilder (com.alibaba.excel.read.builder.ExcelReaderBuilder)5 ExcelReader (com.alibaba.excel.ExcelReader)2 ExcelReadListener (com.dtstack.flinkx.connector.ftp.client.excel.ExcelReadListener)1 ExcelReaderExceptionHandler (com.dtstack.flinkx.connector.ftp.client.excel.ExcelReaderExceptionHandler)1 ExcelReaderExecutor (com.dtstack.flinkx.connector.ftp.client.excel.ExcelReaderExecutor)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1