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

不创建对象用String接收日期类型数据异常 #3767

Open
VisionsOfIdiot opened this issue Apr 16, 2024 · 2 comments
Open

不创建对象用String接收日期类型数据异常 #3767

VisionsOfIdiot opened this issue Apr 16, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@VisionsOfIdiot
Copy link

建议先去看文档

快速开始常见问题

触发场景描述

不创建对象自定义监听器来读取Excel文件,指定了返回类型为String,期望获取Excel单元格内显示的字符串,但是返回的是日期类型的字符串,而非单元格内显示数据
image
image

读取入口

        ExcelHeaderReadListener listener = new ExcelHeaderReadListener();
        EasyExcel.read(file,listener).useDefaultListener(true).sheet(0).doRead();

自定义监听器

package org.example.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.Collections;
import java.util.Map;

public class ExcelHeaderReadListener extends AnalysisEventListener<Map<Integer, String>> {


    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println(headMap);
    }

    @Override
    public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
        System.out.println(integerStringMap);
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
    }
}

提示的异常或者没有达到的效果

image
期望获取到的字符串是1990年10月10日

@VisionsOfIdiot VisionsOfIdiot added the bug Something isn't working label Apr 16, 2024
@VisionsOfIdiot
Copy link
Author

这个是对应的Excel文件
带时间Excel文件.xlsx

@LSL1618
Copy link

LSL1618 commented May 10, 2024

应该是默认的单元格数据转换器的锅,你试试 自定义转换器,可参考这几个类
com.alibaba.excel.converters.date.DateStringConverter
com.alibaba.excel.converters.date.DateNumberConverter
com.alibaba.excel.converters.date.DateDateConverter

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

3 participants