gpt4 book ai didi

java - Excel 模板从 JXLS 1 迁移到 JXLS 2

转载 作者:行者123 更新时间:2023-11-30 07:38:15 25 4
gpt4 key购买 nike

使用 JXLS 1,可以通过简单调用来在 Excel 模板中进行替换

XLSTransformer.transformXLS(is,beans)

例如,我们有 bean 对象,它们的组织方式如下(不太好,好吧..:)):

class Person{
private String name;
private String lastname;
private String tel;
private String gender;
private Integer count;

public Person(String name, String lastname, String telephone, String gender){
this.name = name;
this.lastname = lastname;
this.tel = telephone;
this.gender = gender;
this.count = null;
}

public Person(String gender, int count){
this.gender = gender;
this.count = count;
}
//getters
}

现在,给定这个模板:

template

以及以下初始化:

List<Person> p = Arrays.asList(
new Person(„Johnny“, „Cash“, „1394567“, „M“),
new Person(„Paul“, „Newman“, „234667“, „M“),
new Person(„M“,2),
new Person(„Jessica“, „Alba“, „134566“, „F“),
new Person(„F“,1)
);

Map<String, List<? extends Object>> beans = new HashMap<String, List<? extends Object>>();
beans.put(„persons“, p);
beans.put(„heading“, Arrays.asList(„This is the heading“));

简单的调用

transformer.transformXLS(templateInputStream, beans);

本可以完成这个技巧并生成如下所示的内容:

generated XLS

现在,我需要迁移到 JXLS 2 以便将 SXSSFWorkbook 用于非常大的 XLSX 文件,但我无法成功将好的旧标签转换为它们的注释等效项:在在线文档中,我读到这是可能的将更多表达式组合在一起,例如 jx:each 后跟 jx:if ,它使用循环的变量将生成表达式EvaluationException。

您有任何可能有帮助的提示/示例吗?

提前致谢!

最佳答案

可以找到结合 jx:eachjx:if 命令的模板示例 here看起来像这样

jxls template with combining jx:each and jx:if

Java 代码位于 jxls-demo project

尝试使用这种方法。

如果此后您在 JXLS-2 中实现案例时仍然遇到问题,请在 JXLS 问题跟踪器中提出改进。

关于java - Excel 模板从 JXLS 1 迁移到 JXLS 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35067888/

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