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中包含高管关键词解析失败 #1595

Closed
zhugw opened this issue Sep 26, 2020 · 5 comments
Closed

excel中包含高管关键词解析失败 #1595

zhugw opened this issue Sep 26, 2020 · 5 comments
Assignees
Labels
bug Something isn't working development completed Development completed, waiting for release pending verification This problem needs to be confirmed

Comments

@zhugw
Copy link

zhugw commented Sep 26, 2020

olay.xlsx
发现这么一个问题 使用easyexcel解析Excel的时候 报了如下的错

Caused by: java.lang.NumberFormatException: Character O is neither a decimal digit number, decimal point, nor "e" notation exponential mark.
	at java.base/java.math.BigDecimal.<init>(BigDecimal.java:518)
	at java.base/java.math.BigDecimal.<init>(BigDecimal.java:401)
	at java.base/java.math.BigDecimal.<init>(BigDecimal.java:834)
	at com.alibaba.excel.analysis.v07.handlers.AbstractCellValueTagHandler.endElement(AbstractCellValueTagHandler.java:36)

分析下了Excel 对一些关键词进行了高亮 且高亮的关键词在字符串的开头的话 就会解析失败 如 :

OLAY精华身体乳,按压设计,刚挤出来感觉会有点厚重,但是涂在身上好推开,吸收也很快。

对OLAY进行了高亮 且在字符串的开头的话 就会报错

原因是会将高亮关键词OLAY识别为CellDataTypeEnum.EMPTY类型 然后进入如下的代码分支

            case EMPTY:
                tempCellData.setType(CellDataTypeEnum.NUMBER);
                tempCellData.setNumberValue(new BigDecimal(tempData.toString()));
                break;

就会报上述的错误 不知道为什么会将高亮关键词识别为EMPTY类型?

补充:
问题Excel见附件 问题行是23行

@zhugw zhugw added the bug Something isn't working label Sep 26, 2020
@Albert1881
Copy link
Contributor

请问目前是否有人处理这个bug,我对这个issue感兴趣,会在最近几个月尝试去修复这个bug @zhuangjiaju

@zhugw
Copy link
Author

zhugw commented Mar 12, 2021

@Albert1881
感谢! 终于有人解决这个bug了 目前我的解决办法就是把 com.alibaba.excel.analysis.v07.handlers.AbstractCellValueTagHandler 复制一份到当前应用中 然后做了如下的改写

        CellDataTypeEnum oldType = tempCellData.getType();
        /**
         * tempData: 1592 type: EMPTY
         * tempData: 完美日记 type: EMPTY
         * tempData: 309.33 type: EMPTY
         */
        if (CellDataTypeEnum.EMPTY.equals(oldType)) {
            LOGGER.debug("tempData: {} type: {}", tempData, oldType);
            if (!tempData.toString().matches("[0-9]+") && !tempData.toString().matches("\\d+\\.\\d+")) {
                tempCellData.setType(CellDataTypeEnum.STRING);
                oldType = CellDataTypeEnum.STRING;
                /**
                 * tempData: 完美日记 change type from EMPTY to STRING
                 */
                LOGGER.warn("tempData: {} change type from {} to {}", tempData, CellDataTypeEnum.EMPTY, CellDataTypeEnum.STRING);
            }
        }
        switch (oldType) {

@Albert1881
Copy link
Contributor

好的感谢,我已经复现bug,正在查看可能原因

@zhuangjiaju
Copy link
Collaborator

这个重新保存下exce就行了 这个不符合官方的规范的excel

@zhuangjiaju
Copy link
Collaborator

已经在3.0.0-beta1 版本修复,beta版本会在一个月内升级成正式版。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working development completed Development completed, waiting for release pending verification This problem needs to be confirmed
Projects
None yet
Development

No branches or pull requests

3 participants