AnalysisEventListener.java 1.6 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;
7
import com.alibaba.excel.metadata.CellExtra;
Z
zhuangjiaju 已提交
8
import com.alibaba.excel.read.listener.ReadListener;
庄家钜's avatar
庄家钜 已提交
9
import com.alibaba.excel.util.ConverterUtils;
10 11

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

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

    /**
     * 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) {}

31 32 33 34 35 36 37 38 39 40 41
    /**
     * The current method is called when extra information is returned
     *
     * @param extra
     *            extra information
     * @param context
     *            analysis context
     */
    @Override
    public void extra(CellExtra extra, AnalysisContext context) {}

42
    /**
Z
zhuangjiaju 已提交
43 44
     * All listeners receive this method when any one Listener does an error report. If an exception is thrown here, the
     * entire read will terminate.
45
     *
Z
zhuangjiaju 已提交
46 47
     * @param exception
     * @param context
48
     */
Z
zhuangjiaju 已提交
49 50 51 52
    @Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {
        throw exception;
    }
53

Z
zhuangjiaju 已提交
54
    @Override
Z
zhuangjiaju 已提交
55 56 57
    public boolean hasNext(AnalysisContext context) {
        return true;
    }
58
}