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

建议增加对CSV格式bom头的支持 #3137

Closed
Naylor55 opened this issue Apr 23, 2023 · 3 comments
Closed

建议增加对CSV格式bom头的支持 #3137

Naylor55 opened this issue Apr 23, 2023 · 3 comments
Labels
suggest Suggest

Comments

@Naylor55
Copy link

Naylor55 commented Apr 23, 2023

建议描述

使用版本是 3.1.0 ,在导入CSV 的时候出现了首列无法导入的问题,后来发现是 UTF-8 BOM 编码导致的,已经解决了,解决思路是在获取文件流后先处理bom标识,然后再处理数据的导入。建议官方将此功能集成到框架中。
核心代码如下

    public InputStream getInputStream(InputStream in) throws IOException {
        PushbackInputStream backStream = new PushbackInputStream(in);
        int ch = backStream.read();
        if (ch != 0xEF) {
            backStream.unread(ch);
        } else if ((ch = backStream.read()) != 0xBB) {
            backStream.unread(ch);
            backStream.unread(0xef);
        } else if ((ch = backStream.read()) != 0xBF) {
            throw new IOException("错误的CSV文件");
        } else {
        }
        return backStream;
    }

  data = EasyExcel.read(getInputStream(file.getInputStream())).excelType(ExcelTypeEnum.CSV).head(XXX.class).sheet().doReadSync();
           

@Naylor55 Naylor55 added the suggest Suggest label Apr 23, 2023
@gongxuanzhang
Copy link
Collaborator

#3019
等待合并了

zhuangjiaju added a commit that referenced this issue Apr 28, 2023
* 解决csv用office打开乱码的问题,写csv默认带上BOM数据
@zhuangjiaju
Copy link
Collaborator

已经在最新版本修复

@codesong99
Copy link

#3297 导出字节流也建议支持一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggest Suggest
Projects
None yet
Development

No branches or pull requests

4 participants