まず、データを保持するために以下のような POJO が必要です。
public class Employee {
private int id = 0;
private String name = null;
private List<String> mails = new ArrayList<String>();
// getters & setters
}
次に、Excel ファイルに表示するデータ オブジェクトを作成します。
Employee emp1 = new Employee();
emp1.setId(1);
emp1.setName("AAA");
emp1.getMails().add("aaa1@xyz.com");
emp1.getMails().add("aaa2@xyz.com");
Employee emp2 = new Employee();
emp2.setId(2);
emp2.setName("BBB");
emp2.getMails().add("bbb1@xyz.com");
emp2.getMails().add("bbb2@xyz.com");
List<Employee> employees = new ArrayList<Employee>();
employees.add(emp1);
employees.add(emp2);
次に、データを java.util.Map に追加します
Map<String, List<Employee>> beanParams = new HashMap<String, List<Employee>>();
beanParams.put("employees", employees);
次に、XLSTransformer オブジェクトを作成し、ソース ファイル、宛先ファイル、およびデータを保持するマップを設定します。
XLSTransformer former = new XLSTransformer();
former.transformXLS(srcFilePath, beanParams, destFilePath);
2 つの タグを使用してマップ内のリストを反復処理する必要があり<jx:forEach>
、結果の Excel ファイルに値を設定できます。
Excel テンプレート ファイルを次のように変更します。

最終結果は次のようになります
