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

多sheet首次写入顺序和传入序号不一致时数据覆盖重叠 #1332

Closed
LinWanCen opened this issue May 21, 2020 · 1 comment
Closed
Labels
pending verification This problem needs to be confirmed

Comments

@LinWanCen
Copy link

LinWanCen commented May 21, 2020

通过分析已经定位到相应的框架源代码位置了:

try {
if (writeSheetHolder.getSheetNo() != null) {
currentSheet = writeWorkbookHolder.getWorkbook().getSheetAt(writeSheetHolder.getSheetNo());
writeSheetHolder
.setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheetAt(writeSheetHolder.getSheetNo()));
} else {
// sheet name must not null
currentSheet = writeWorkbookHolder.getWorkbook().getSheet(writeSheetHolder.getSheetName());
writeSheetHolder
.setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheet(writeSheetHolder.getSheetName()));
}
} catch (Exception e) {
currentSheet = createSheet();
}

这段代码是用表序号去查,查不到就创建一个表,但是创建的表序号和获取的表序号并不一致

使用场景抽象:

        WriteSheet totalSheet = EasyExcel
                .writerSheet(1, "总分")
                .head(DownloadData.class)
                .registerWriteHandler(new FreezeAndFilter())
                .build();
        WriteSheet detailSheet = EasyExcel
                .writerSheet(2, "明细")
                .head(DownloadData.class)
                .registerWriteHandler(new FreezeAndFilter())
                .build();
        // WriteSheet logSheet = null;
        WriteSheet logSheet = EasyExcel
                .writerSheet(3, "日志")
                .head(LogData.class)
                .registerWriteHandler(new FreezeAndFilter())
                .build();
for (EvalScoreDO evalScoreDO : cursor) {
    writer.write(Collections.singletonList(detailData), detailSheet);
    ifbool1){
        writer.write(Collections.singletonList(new LogData(level, msg)), logSheet);
    }
    ifbool2){
        writer.write(Collections.singletonList(totalsData), totalSheet);
    }
}

这里如果某条数据有错先写入了日志就会导致日志和明细的数据重叠覆盖,
目前我暂时调换了日志和总分的顺序,并通过代码逻辑确保数据首次写入顺序一致。

@zhuangjiaju
Copy link
Collaborator

非常感谢您的意见,已经在最新版修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending verification This problem needs to be confirmed
Projects
None yet
Development

No branches or pull requests

2 participants