// Create a new workbook Workbook workbook = new Workbook(); //Load template file from resource InputStream templateFile = this.getResourceStream("xlsx/Template_MedicalReport.xlsx"); workbook.open(templateFile); //Here in the demo, we use a mock class to generate instance of java.sql.ResultSet. //User who use template in product, must get instance of java.sql.ResultSet from the //related database connection. MyTableDataSource datasource = new MyTableDataSource(this.getResourceStream("data/medical report.csv")); //Init template global settings workbook.getNames().add("TemplateOptions.KeepLineSize", "true"); workbook.getNames().add("TemplateOptions.InsertMode", "EntireRowColumn"); //Add data source workbook.addDataSource("ds", datasource); //Invoke to process the template workbook.processTemplate(); // Save to an excel file workbook.save("MedicalReport.xlsx");