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

如何合并单元格 #415

Open
wonktondI opened this issue Jan 26, 2024 · 12 comments
Open

如何合并单元格 #415

wonktondI opened this issue Jan 26, 2024 · 12 comments

Comments

@wonktondI
Copy link

Bug描述
描述Bug产生的现象(A clear and concise description of what the bug is.)
image
这些单元格如何合并?
Bug复现
按如下步骤复现(Steps to reproduce the behavior):
实体类定义
image

期望的结果
期望的结果是什么(A clear and concise description of what you expected to happen.)
合并后的效果
image

@wonktondI
Copy link
Author

wonktondI commented Apr 28, 2024

https://github.com/liaochong/myexcel/wiki/%E8%81%9A%E5%90%88%E5%88%97&%E5%86%85%E8%81%9A%E5%AF%BC%E5%87%BA 参考这个

参考的头条的实例
导出后,并没有合并相同的列 实体类字段注解是上面的截图
image

@tkl2wf
Copy link

tkl2wf commented Apr 29, 2024

我在聚合导出文档 ExtendedInfo,List studentNames,又加了个@MultiColumn(classType = String.class),,然后用流导出,可以实现效果了,我把School改为Educational,主要是用流的autoMerge,而且要在start之前,用DefaultStreamExcelBuilder,不是DefaultExcelBuilder
DefaultStreamExcelBuilder defaultExcelBuilder = DefaultStreamExcelBuilder.of(Educational.class).autoMerge().start();
defaultExcelBuilder.append(eduList);
workbook = defaultExcelBuilder.build();

@tkl2wf
Copy link

tkl2wf commented Apr 29, 2024

11
22
33

@wonktondI
Copy link
Author

11 22 33

这是实现代码:
image
实体类:
image
关联的类
image

按照图示代码,我关联类里的两个字段得类型得都是List才行,才能实现聚合的效果?

@tkl2wf
Copy link

tkl2wf commented Apr 29, 2024

恐怕是这么回事,我最近也是有合并的需求,而且我那个还是map的,准备自己循环判断合并了,

@wonktondI
Copy link
Author

恐怕是这么回事,我最近也是有合并的需求,而且我那个还是map的,准备自己循环判断合并了,

关联类里的字段都得是List才能合并,单字段的试过可以了。多字段的不清楚。你这个有示例代码吗

@liaochong
Copy link
Owner

必须是List才能合并,因为需要根据list的长度提前设置合并长度

@liaochong
Copy link
Owner

如果是map导出,可以使用DefaultStreamExcelBuilder+模板导出的方式,也可以比较快速实现你需要的效果

@tkl2wf
Copy link

tkl2wf commented Apr 29, 2024

如果是map导出,可以使用DefaultStreamExcelBuilder+模板导出的方式,也可以比较快速实现你需要的效果

好的,感谢

@wonktondI
Copy link
Author

感谢,我直接两个list导出了

@tkl2wf
Copy link

tkl2wf commented Apr 29, 2024

对的,几个属性就用几个list就可以,

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

3 participants