AnalysisEventListener.java 1.3 KB
Newer Older
1 2
package com.alibaba.excel.event;

庄家钜's avatar
庄家钜 已提交
3 4
import java.util.Map;

5
import com.alibaba.excel.context.AnalysisContext;
庄家钜's avatar
庄家钜 已提交
6
import com.alibaba.excel.metadata.CellData;
Z
zhuangjiaju 已提交
7
import com.alibaba.excel.read.listener.ReadListener;
庄家钜's avatar
庄家钜 已提交
8
import com.alibaba.excel.util.ConverterUtils;
9 10

/**
Z
zhuangjiaju 已提交
11
 * Receives the return of each piece of data parsed
12 13 14
 *
 * @author jipengfei
 */
Z
zhuangjiaju 已提交
15
public abstract class AnalysisEventListener<T> implements ReadListener<T> {
16

庄家钜's avatar
庄家钜 已提交
17 18
    @Override
    public void invokeHead(Map<Integer, CellData> headMap, AnalysisContext context) {
庄家钜's avatar
庄家钜 已提交
19
        invokeHeadMap(ConverterUtils.convertToStringMap(headMap, context), context);
庄家钜's avatar
庄家钜 已提交
20 21 22 23 24 25 26 27 28 29
    }

    /**
     * Returns the header as a map.Override the current method to receive header data.
     *
     * @param headMap
     * @param context
     */
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {}

30
    /**
Z
zhuangjiaju 已提交
31 32
     * All listeners receive this method when any one Listener does an error report. If an exception is thrown here, the
     * entire read will terminate.
33
     *
Z
zhuangjiaju 已提交
34 35
     * @param exception
     * @param context
36
     */
Z
zhuangjiaju 已提交
37 38 39 40
    @Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {
        throw exception;
    }
41

Z
zhuangjiaju 已提交
42
    @Override
Z
zhuangjiaju 已提交
43 44 45
    public boolean hasNext(AnalysisContext context) {
        return true;
    }
46
}