gpt4 book ai didi

java - JXLS。如何将不同的集合放入不同的工作表中?

转载 作者:行者123 更新时间:2023-11-30 02:31:06 25 4
gpt4 key购买 nike

我正在尝试将两个集合放入 Excel 文档中。我正在这样做:

context.putVar("collection1", collection1);
context.putVar("collection2", collection2);
xlsHelper.getInstance().processTemplate(getClass().getClassLoader().getResourceAsStream("templates/exceldocument.xls"), os, context);

Excel 文档有两张表,一张是collection1,另一张是collection2

但是当我这样做时,只有一个集合被放入一张纸中。

如何将两个集合放在不同的工作表中?

最佳答案

您可以构建 XLS 区域列表并根据需要手动处理它们。代码可以是这样的

Transformer transformer = TransformerFactory.createTransformer(is, os);
AreaBuilder areaBuilder = new XlsCommentAreaBuilder(transformer);
List<Area> xlsAreaList = areaBuilder.build();
Area sheet1Area = xlsAreaList.get(0);
Area sheet2Area = xlsAreaList.get(1);
sheet1Area.applyAt(new CellRef("sheet1!A1"), context); // process sheet1
sheet2Area.applyAt(new CellRef("sheet2!A1"), context); // process sheet2
transformer.write();

实际上,向 JxlsHelper 添加类似的支持非常容易,因此请随时在 Jxls issue tracker 中提出改进。改进JxlsHelper

另请参阅XlsCommentBuilderDemo更全面示例的示例代码。

关于java - JXLS。如何将不同的集合放入不同的工作表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44256151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com