// Create a new workbook Workbook workbook = new Workbook(); //Load template file from resource InputStream templateFile = this.getResourceStream("xlsx/Template_MultiColumnSort.xlsx"); workbook.open(templateFile); //#region Define custom classes // public class OrderItem { // public String orderId; // public String customer; // public Date date; // public double sales; // // public OrderItem(String orderId, String customer, Date date, double sales) { // this.orderId = orderId; // this.customer = customer; // this.date = date; // this.sales = sales; // } // } //#endregion List datasource = new ArrayList(); //#region Init Data datasource.add(new OrderItem("10001", "Noah Taylor", new Date(124, 0, 20), 1620.25)); datasource.add(new OrderItem("10002", "William Smith", new Date(124, 0, 20), 5620.25)); datasource.add(new OrderItem("10003", "Sophia Miller", new Date(124, 0, 20), 3354.50)); datasource.add(new OrderItem("10004", "Noah Taylor", new Date(124, 0, 23), 3563.00)); datasource.add(new OrderItem("10005", "Ava Johnson", new Date(124, 0, 23), 1500.00)); datasource.add(new OrderItem("10006", "Ava Davis", new Date(124, 0, 24), 3500.00)); datasource.add(new OrderItem("10007", "Emma Brown", new Date(124, 0, 24), 8865.50)); datasource.add(new OrderItem("10008", "Isabella Taylor", new Date(124, 0, 24), 4332.05)); datasource.add(new OrderItem("10009", "Noah Anderson", new Date(124, 0, 25), 5568.54)); datasource.add(new OrderItem("10010", "William Smith", new Date(124, 0, 26), 2659.56)); datasource.add(new OrderItem("10011", "Liam Taylor", new Date(124, 0, 26), 6659.56)); datasource.add(new OrderItem("10012", "Olivia Smith", new Date(124, 0, 26), 4321.05)); datasource.add(new OrderItem("10013", "Emma Brown", new Date(124, 0, 27), 6521.52)); datasource.add(new OrderItem("10014", "Ava Jones", new Date(124, 0, 28), 4321.05)); datasource.add(new OrderItem("10015", "Liam Johnson", new Date(124, 0, 28), 5542.02)); //#endregion //Init template global settings workbook.getNames().add("TemplateOptions.KeepLineSize", "true"); //Add data source workbook.addDataSource("ds", datasource); //Invoke to process the template workbook.processTemplate(); // Save to an excel file workbook.save("TemplateMultiColumnSort.xlsx");