javaspringjxls

When iterating a list of fields are not displayed jxls


I have 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;
        }
    }

And the template example that I downloaded from http://jxls.sourceforge.net/getting_started.html

enter image description here

My code in service

 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);

and result file

enter image description here

But if write in template

enter image description here

Result

enter image description here


Solution

  • You should fill all table part columns in the template (cells A4:D4)

    Your template: OP's template

    Must be set as: Working template