// Create a new workbook Workbook workbook = new Workbook(); //Load template file from resource InputStream templateFile = this.getResourceStream("xlsx/Template_SalesDataGroup_ResultSet.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. java.sql.ResultSet datasource = new MockResultSet(new DataTable(this.getResourceStream("data/sales.csv"))); //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("ResultSet.xlsx");