com.alibaba.excel.event.AnalysisEventListener Java Examples

The following examples show how to use com.alibaba.excel.event.AnalysisEventListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExcelToolUtil.java    From spring-microservice-exam with MIT License 6 votes vote down vote up
/**
 * 导入Excel
 * @param inputStream inputStream
 * @param clazz clazz
 * @param listener listener
 * @return boolean
 */
public static <T> Boolean readExcel(InputStream inputStream, Class<T> clazz, AnalysisEventListener<T> listener) {
	Boolean success = Boolean.TRUE;
	ExcelReader excelReader = null;
	try {
		excelReader = EasyExcelFactory.read(inputStream, clazz, listener).build();
		ReadSheet readSheet = EasyExcelFactory.readSheet(0).build();
		excelReader.read(readSheet);
	} catch (Exception e) {
		log.error("Read excel error: {}", e.getMessage(), e);
		success = Boolean.FALSE;
	} finally {
		if (excelReader != null)
			excelReader.finish();
	}
	return success;
}
 
Example #2
Source File: ExcelReader.java    From easyexcel with Apache License 2.0 6 votes vote down vote up
/**
 * Create new reader
 *
 * @param in
 *            the POI filesystem that contains the Workbook stream
 * @param excelTypeEnum
 *            03 or 07
 * @param customContent
 *            {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext
 * @param eventListener
 *            Callback method after each row is parsed.
 * @param trim
 *            The content of the form is empty and needs to be empty. The purpose is to be fault-tolerant, because
 *            there are often table contents with spaces that can not be converted into custom types. For example:
 *            '1234 ' contain a space cannot be converted to int.
 * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader'
 */
@Deprecated
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
    AnalysisEventListener eventListener, boolean trim) {
    ReadWorkbook readWorkbook = new ReadWorkbook();
    readWorkbook.setInputStream(in);
    readWorkbook.setExcelType(excelTypeEnum);
    readWorkbook.setCustomObject(customContent);
    if (eventListener != null) {
        List<ReadListener> customReadListenerList = new ArrayList<ReadListener>();
        customReadListenerList.add(eventListener);
        readWorkbook.setCustomReadListenerList(customReadListenerList);
    }
    readWorkbook.setAutoTrim(trim);
    readWorkbook.setAutoCloseStream(Boolean.FALSE);
    readWorkbook.setMandatoryUseInputStream(Boolean.TRUE);
    readWorkbook.setReadCache(new MapCache());
    readWorkbook.setConvertAllFiled(Boolean.FALSE);
    readWorkbook.setDefaultReturnMap(Boolean.FALSE);
    // The previous logic was that Article 0 started reading
    readWorkbook.setHeadRowNumber(0);
    excelAnalyser = new ExcelAnalyserImpl(readWorkbook);
}
 
Example #3
Source File: ExcelReader.java    From easyexcel with Apache License 2.0 2 votes vote down vote up
/**
 * Create new reader
 *
 * @param in
 *            the POI filesystem that contains the Workbook stream
 * @param excelTypeEnum
 *            03 or 07
 * @param customContent
 *            {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext
 * @param eventListener
 *            Callback method after each row is parsed.
 * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader'
 */
@Deprecated
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
    AnalysisEventListener eventListener) {
    this(in, excelTypeEnum, customContent, eventListener, true);
}
 
Example #4
Source File: ExcelReader.java    From easyexcel with Apache License 2.0 2 votes vote down vote up
/**
 * Create new reader
 *
 * @param in
 *            the POI filesystem that contains the Workbook stream
 * @param customContent
 *            {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext
 * @param eventListener
 *            Callback method after each row is parsed
 * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader'
 */
@Deprecated
public ExcelReader(InputStream in, Object customContent, AnalysisEventListener eventListener) {
    this(in, customContent, eventListener, true);
}
 
Example #5
Source File: ExcelReader.java    From easyexcel with Apache License 2.0 2 votes vote down vote up
/**
 * Create new reader
 *
 * @param param
 *            old param Deprecated
 * @param eventListener
 *            Callback method after each row is parsed.
 * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader'
 */
@Deprecated
public ExcelReader(AnalysisParam param, AnalysisEventListener eventListener) {
    this(param.getIn(), param.getExcelTypeEnum(), param.getCustomContent(), eventListener, true);
}
 
Example #6
Source File: ExcelReader.java    From easyexcel with Apache License 2.0 2 votes vote down vote up
/**
 * Create new reader
 *
 * @param in
 * @param customContent
 *            {@link AnalysisEventListener#invoke(Object, AnalysisContext) }AnalysisContext
 * @param eventListener
 * @param trim
 *            The content of the form is empty and needs to be empty. The purpose is to be fault-tolerant, because
 *            there are often table contents with spaces that can not be converted into custom types. For example:
 *            '1234 ' contain a space cannot be converted to int.
 * @deprecated please use {@link EasyExcelFactory#read()} build 'ExcelReader'
 */
@Deprecated
public ExcelReader(InputStream in, Object customContent, AnalysisEventListener eventListener, boolean trim) {
    this(in, null, customContent, eventListener, trim);
}
 
Example #7
Source File: EasyExcelFactory.java    From easyexcel with Apache License 2.0 2 votes vote down vote up
/**
 * Parsing large file
 *
 * @param in
 *            the POI filesystem that contains the Workbook stream.
 * @param sheet
 *            read sheet.
 * @param listener
 *            Callback method after each row is parsed.
 * @deprecated please use 'EasyExcel.read(in,head,listener).sheet(sheetNo).doRead();'
 */
@Deprecated
public static void readBySax(InputStream in, Sheet sheet, AnalysisEventListener listener) {
    new ExcelReader(in, null, listener).read(sheet);
}
 
Example #8
Source File: EasyExcelFactory.java    From easyexcel with Apache License 2.0 2 votes vote down vote up
/**
 * Get ExcelReader.
 *
 * @param in
 *            the POI filesystem that contains the Workbook stream.
 * @param listener
 *            Callback method after each row is parsed.
 * @return ExcelReader.
 * @deprecated please use {@link EasyExcel#read()} build 'ExcelReader'
 */
@Deprecated
public static ExcelReader getReader(InputStream in, AnalysisEventListener listener) {
    return new ExcelReader(in, null, listener);
}