Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excel最后一列没有数据,只有表头,但是读取数据的时候不会把最后一列的空数据读到map里,导致表头数据和实际数据数量对不上 #4033

Open
GSLX-LEO opened this issue Oct 24, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@GSLX-LEO
Copy link

GSLX-LEO commented Oct 24, 2024

【场景】
导入excel文件,表头有6列,但是数据只有前5列有,最后一列数据为空
image

通过继承AnalysisEventListener类重写invoke方法,读取的的data中,表头map的size为6,第一行数据map的size为5,没有统计最后一列为空的data数据;

【 触发Bug的代码】

public class DynamicReadListener extends AnalysisEventListener<Map<Integer, Object>> {

    //Excel数据缓存结构
    private List<Map<Integer, Map<Integer, Object>>> list;
    private List<Map<Integer, String>> headList = new ArrayList<>();
    //Excel表头(列名)数据缓存结构
    private Map<Integer, String> headTitleMap = new HashMap<>();

    public DynamicReadListener() {
        list = new ArrayList<>();
    }

    /** 解析表头外的所有行数据 **/
    public void invoke(Map<Integer, Object> data, AnalysisContext context) {
        Map<Integer, Map<Integer, Object>> map = new HashMap<>();
        map.put(context.readRowHolder().getRowIndex(), data);
        list.add(map);
    }

    /** 解析完的后置操作 **/
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info(HikLog.toLog("all data analysed..."));
    }

    /** 解析表头数据 **/
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        headTitleMap = headMap;
        headList.add(headMap);
    }

}

其中headMap的size为6,但是invoke方法获取的data的size为5.

【提示的异常或者没有达到的效果】
怀疑是以下两个地方存在问题:
image
image

@GSLX-LEO GSLX-LEO added the bug Something isn't working label Oct 24, 2024
@GSLX-LEO GSLX-LEO changed the title excel excel最后一列没有数据,只有表头,但是读取数据的时候不会把最后一列的空数据读到map里,导致表头数据和实际数据数量对不上 Oct 24, 2024
@psxjoy
Copy link
Collaborator

psxjoy commented Oct 24, 2024

It’s definitely a bug, and we’re in the process of evaluating it and working on a fix.

@gongxuanzhang
Copy link
Collaborator

I can't try to reproduce this problem, can you provide a copy of the original excel and the code to read excel
@GSLX-LEO

@alibaba alibaba deleted a comment Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants