Search code examples
javaexceljxls

Jxls2 dynamic columns


Currently, i have a List<MyClass> would like to display and repeat over columns.

    Class MyClass {
       String attr1;
       String attr2;
       String attr3;
    }

In Jxls 1.0.6, it could be defined by

    B1 -- <jx:forEach items="${myList}" var="m">
    C1 -- ${m.attr1}
    D1 -- ${m.attr2}
    E1 -- ${m.attr3}
    F1 -- </jx:forEach>

As of the performance issue, I am going to upgrade to Jxls 2.2.3.

In this, I see there is an option of "direction" for a each command. So, I set the comment field in A1 as follows.

    jx:each(items="myList" var="m" lastCell="C1" area="A1:C1" direction=EachCommand.Direction.RIGHT)

and input these for the columns

    A1 -- ${m.attr1}
    B1 -- ${m.attr2}
    C1 -- ${m.attr3}

However, the output of the excel is

A1 B1 C1
X X X
X X X
X X X
....

and my exception is display like

A1 B1 C1 D1 E1 F1 G1 H1 I1 J1
X X X X X X X X X ......

Is there any way to do it by the excel comment field and how to do if yes?

Thanks!


Solution

    1. Upgrade to jxls-2.2.4 (it was just released)
    2. Use the following syntax to specify RIGHT direction for Each-command

      jx:each(items="myList" var="m" lastCell="C1" area="A1:C1" direction="RIGHT")