Search code examples
jxls

How to reference a dynamic range inside an each in JXLS?


I've made a template with two jx:each statements. The first references the other and should lookup a value among all the columns in the second table.

It looks something like this:

A1: jx:each(items="employees" var="employee" lastCell="A2")

A1:${employee.id} A2:=INDEKS(C1;MATCH(A1;C1;0))

B1:

C1: jx:each(items="salaries" var="salary" lastCell="C1")

C1:${salary.employeeId} C2:${salary.value}

So what I'm trying to do here is to list all employees, and for each show the salary. The loops are working fine. But the problem is that when rows are being repeated in the first loop, the formula iterates over rows in the second instead of creating a range:

What I get:

A1:emp1 A2:=INDEX(F2;MATCH(A1;F2;0))
B1:emp2 B2:=INDEX(G2;MATCH(B1;G2;0))
C1:emp3 C2:=INDEX(G2;MATCH(C1;H2;0))
D1:emp4 D2:=INDEX(G2;MATCH(D1;I2;0))

E1:

F1: emp1 F2: 100,000
G1: emp1 G2: 100,020
H1: emp1 H2: 100,040
I1: emp1 I2: 100,060

What I want:

A1:emp1 A2:=INDEKS(F2:H2;MATCH(A1;F2:H2;0))
B1:emp2 B2:=INDEKS(F2:H2;MATCH(B1;F2:H2;0))
C1:emp3 C2:=INDEKS(F2:H2;MATCH(C1;F2:H2;0))
D1:emp4 D2:=INDEKS(F2:H2;MATCH(D1;F2:H2;0))

Solution

  • Try to set standard formula processor with

      xlsArea.setFormulaProcessor(new StandardFormulaProcessor());
    

    and see if it helps.