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

多个WriteSheet都注册WorkbookWriteHandler,仅有最后一个WriteSheet注册的生效 #4047

Open
brged opened this issue Nov 8, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@brged
Copy link

brged commented Nov 8, 2024

触发场景描述

多个WriteSheet都注册了WorkbookWriteHandler,但仅有全局和最后一个WriteSheet的生效

触发Bug的代码

        File file = new File("test-2.xlsx");
        try (ExcelWriter excelWriter = EasyExcel.write(file).excelType(ExcelTypeEnum.XLSX)
                .registerWriteHandler(new WorkbookWriteHandler() {
                    @Override
                    public void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
                        WorkbookWriteHandler.super.afterWorkbookDispose(context);
                        System.out.println("-----global");
                        System.out.println("-----global");
                    }
                })
                .build();
        ) {
            WriteSheet writeSheet = EasyExcel.writerSheet(0, "模板0").head(DemoData.class)
                    .registerWriteHandler(new WorkbookWriteHandler() {
                        @Override
                        public void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
                            WorkbookWriteHandler.super.afterWorkbookDispose(context);
                            System.out.println("---------模板0");
                            System.out.println("---------模板0");
                            System.out.println("---------模板0");
                        }
                    })
                    .build();
            excelWriter.write(Test02::data, writeSheet);

            WriteSheet writeSheet1 = EasyExcel.writerSheet(1, "模板1")
                    .head(DemoData.class)
                    .registerWriteHandler(new WorkbookWriteHandler() {
                        @Override
                        public void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
                            WorkbookWriteHandler.super.afterWorkbookDispose(context);
                            System.out.println("---------模板1模板1");
                            System.out.println("---------模板1模板1");
                            System.out.println("---------模板1模板1");
                        }
                    })
                    .build();
            excelWriter.write(Test02::data, writeSheet1);


            WriteSheet writeSheet2 = EasyExcel.writerSheet(2, "模板2")
                    .head(DemoData.class)
                    .registerWriteHandler(new WorkbookWriteHandler() {
                        @Override
                        public void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
                            WorkbookWriteHandler.super.afterWorkbookDispose(context);
                            System.out.println("---------模板2");
                            System.out.println("---------模板2");
                            System.out.println("---------模板2");
                        }
                    })
                    .build();
            excelWriter.write(Test02::data, writeSheet2);

        }

提示的异常或者没有达到的效果

输出

---------模板2
---------模板2
---------模板2
-----global
-----global

仅有全局和最后一个WriteSheet的WorkbookWriteHandler生效

@brged brged added the bug Something isn't working label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants