public class JXLSReportGenerator {
public static void main(String[] args) throws IOException, InvalidFormatException {
InputStream templateInputStream = new FileInputStream("template.xlsx");
Workbook workbook = WorkbookFactory.create(templateInputStream);
List<Person> persons = new ArrayList<>();
persons.add(new Person("John Doe", 25));
persons.add(new Person("Jane Smith", 30));
Context context = new Context();
context.putVar("persons", persons);
JxlsHelper.getInstance().processTemplate(context, workbook.getSheetAt(0));
OutputStream outputStream = new FileOutputStream("report.xlsx");
workbook.write(outputStream);
templateInputStream.close();
outputStream.close();
workbook.close();
}
private static class Person {
private String name;
private int age;
}
}