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导出时,数据长度为空没有导出操作 #77

Open
iwangbowen opened this issue Apr 2, 2024 · 2 comments
Open

单sheet导出时,数据长度为空没有导出操作 #77

iwangbowen opened this issue Apr 2, 2024 · 2 comments

Comments

@iwangbowen
Copy link

iwangbowen commented Apr 2, 2024

问题说明

查看源码,定义了SingleSheetWriteHandlerManySheetWriteHandler来进行相应导出操作,里面的support方法来判断使用哪一个类。由于数据长度为零,两次support调用都返回false,导致没有文件导出。

数据为空时不进行导出,不太符合一般的业务逻辑,这种情况下导出空的文件更符合预期。希望维护者能更新这一块的逻辑,或让用户通过参数自定义导出行为。

临时解决方法

如果想临时修改这部分逻辑,可以实现自定义的SingleSheetWriteHandler,修改默认support实现。

代码示例

@Component
public class MySingleSheetWriteHandler extends SingleSheetWriteHandler {

    public MySingleSheetWriteHandler(ExcelConfigProperties configProperties,
            ObjectProvider<List<Converter<?>>> converterProvider, WriterBuilderEnhancer excelWriterBuilderEnhance) {
        super(configProperties, converterProvider, excelWriterBuilderEnhance);
    }

    @Override
    public boolean support(Object obj) {
        if (obj instanceof List) {
            List<?> objList = (List<?>) obj;

            if (objList.isEmpty()) {
                return true;
            }

            return !(objList.get(0) instanceof List);
        } else {
            throw new ExcelException("@ResponseExcel 返回值必须为List类型");
        }
    }

}
@lltx
Copy link
Collaborator

lltx commented Apr 2, 2024

如果为空的话,此时无法读取到第一行的具体标题

@iwangbowen
Copy link
Author

如果为空的话,此时无法读取到第一行的具体标题

这个时候返回一个空的文件比什么都不做更符合预期

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