public class Employee {
private String name;
private String jobTitle;
}
public class ExcelReportGenerator {
public static void generateReport(List<Employee> employees) throws IOException, ParseException, InvalidFormatException {
try (InputStream inputStream = new FileInputStream("template.xlsx")) {
try (OutputStream outputStream = new FileOutputStream("report.xlsx")) {
Context context = new PoiContext();
JxlsHelper.getInstance().processTemplate(context, new XLSTransformer(), inputStream, outputStream, new HashMap<String, Object>() {{
put("employees", employees);
}});
}
}
}
public static void main(String[] args) throws IOException, ParseException, InvalidFormatException {
List<Employee> employees = new ArrayList<>();
employees.add(employee1);
employees.add(employee2);
generateReport(employees);
}
}