Excel模板从JXLS 1迁移到JXLS 2

时间:2016-01-28 17:18:54

标签: java excel jxls

使用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:每个 ,然后是 jx:if 使用循环变量将生成表达式EvaluationException。

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

提前致谢!

1 个答案:

答案 0 :(得分:0)

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

jxls template with combining jx:each and jx:if

Java代码位于jxls-demo project

尝试使用这种方法。

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