迭代字段列表时不显示 jxls
When iterating a list of fields are not displayed jxls
我有class
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
class Employee implements Serializable {
private String name;
private LocalDate birthDate;
private Double payment;
private Double bonus;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getBirthDate() {
return birthDate;
}
public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
}
public Double getPayment() {
return payment;
}
public void setPayment(Double payment) {
this.payment = payment;
}
public Double getBonus() {
return bonus;
}
public void setBonus(Double bonus) {
this.bonus = bonus;
}
}
以及我从 http://jxls.sourceforge.net/getting_started.html
下载的模板示例
我的代码在使用中
InputStream inputStream = new FileInputStream("/home/maadin/object_collection_template.xls");
List<Employee> employees = Arrays.asList(
new Employee("first employee", LocalDate.of(2020, 10, 10), 100.00, 100.120),
new Employee("second_employee", LocalDate.of(2020, 10, 11), 100.00, 1000.122)
);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Context context = new Context();
context.putVar("employees", employees);
JxlsHelper jxlsHelper = JxlsHelper.getInstance();
jxlsHelper.processTemplate(inputStream, outputStream, context);
return this.toResource(outputStream);
和结果文件
但是如果写在模板里
结果
您应该填写模板中的所有 table 部分列(单元格 A4:D4)
您的模板:
必须设置为:
我有class
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
class Employee implements Serializable {
private String name;
private LocalDate birthDate;
private Double payment;
private Double bonus;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getBirthDate() {
return birthDate;
}
public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
}
public Double getPayment() {
return payment;
}
public void setPayment(Double payment) {
this.payment = payment;
}
public Double getBonus() {
return bonus;
}
public void setBonus(Double bonus) {
this.bonus = bonus;
}
}
以及我从 http://jxls.sourceforge.net/getting_started.html
下载的模板示例我的代码在使用中
InputStream inputStream = new FileInputStream("/home/maadin/object_collection_template.xls");
List<Employee> employees = Arrays.asList(
new Employee("first employee", LocalDate.of(2020, 10, 10), 100.00, 100.120),
new Employee("second_employee", LocalDate.of(2020, 10, 11), 100.00, 1000.122)
);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Context context = new Context();
context.putVar("employees", employees);
JxlsHelper jxlsHelper = JxlsHelper.getInstance();
jxlsHelper.processTemplate(inputStream, outputStream, context);
return this.toResource(outputStream);
和结果文件
但是如果写在模板里
结果
您应该填写模板中的所有 table 部分列(单元格 A4:D4)
您的模板:
必须设置为: