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

导入行数据乱序 #373

Closed
strive10 opened this issue Apr 1, 2024 · 6 comments
Closed

导入行数据乱序 #373

strive10 opened this issue Apr 1, 2024 · 6 comments

Comments

@strive10
Copy link

strive10 commented Apr 1, 2024

读取的row对象中,列数据的顺序和excel实际的顺序不一致。

@wangguanquan
Copy link
Owner

wangguanquan commented Apr 1, 2024 via email

@strive10
Copy link
Author

邮件已发,请查收。

@wangguanquan
Copy link
Owner

已收

@wangguanquan
Copy link
Owner

你发的文件是改动过后的吧,我没有看到乱序。乱序大部分情况是出现了未知的标签导致的兼容性错误,用office打开后再保存Office会删除或修正这部分信息所以再次读就不会有问题,如果要解决问题我需要原件分析是那些标签并做兼容处理

@wangguanquan
Copy link
Owner

EEC不支持多线程读写,它是线程不安全的,内部很多设计都是内存共享的,如果数据量较大需要异步操作可以先将行数据转为对象或者Map后再异步处理逻辑,或者直接使用流式处理参考WIKI

try (ExcelReader reader = ExcelReader.read(Paths.get("./goods.xlsx"))) {
    List<Goods> batch = new ArrayList<>(100);
    for (Iterator<Row> ite = reader.sheet(0).dataIterator(); ite.hasNext(); ) {
        // 行数据转对象
        batch.add(ite.next().to(Goods.class)); // 使用 to 方法将共享的row转为独立的对象,这样就不会互相影响了
        // 满100条批量上架
        if (batch.size() >= 100) {
            goodsService.batchPublish(batch);
            batch.clear();
        }
    }
    // 上架剩余商品
    if (!batch.isEmpty()) {
        goodsService.batchPublish(batch);
    }
} catch (IOException ex) {
    ex.printStackTrace();
}

@wangguanquan
Copy link
Owner

升级到0.5.x解决此问题

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

No branches or pull requests

2 participants