//create a new workbook Workbook workbook = new Workbook(); //Load template file Template_StudentInfo.xlsx from resource InputStream templateFile = this.getResourceStream("xlsx/Template_StudentInfo.xlsx"); workbook.open(templateFile); ///#region Define custom classes //public class StudentInfo //{ // public String name; // public String address; // public ArrayList family; //} ///#region Init Data ArrayList studentInfos = new ArrayList(); StudentInfo student1 = new StudentInfo(); student1.name = "Jane"; student1.address = "101, Halford Avenue, Fremont, CA"; studentInfos.add(student1); StudentInfo student2 = new StudentInfo(); student2.name = "Mark"; student2.address = "2005 Klamath Ave APT, Santa Clara, CA"; studentInfos.add(student2); StudentInfo student3 = new StudentInfo(); student3.name = "Carol"; student3.address = "1063 E EI Camino Real, Sunnyvale, CA 94087, USA"; studentInfos.add(student3); StudentInfo student4 = new StudentInfo(); student4.name = "Liano"; student4.address = "1977 St Lawrence Dr, Santa Clara, CA 95051, USA"; studentInfos.add(student4); StudentInfo student5 = new StudentInfo(); student5.name = "Hellen"; student5.address = "3661 Peacock Ct, Santa Clara, CA 95051, USA"; studentInfos.add(student5); String className = "Class 3"; ///#endregion //Add data source workbook.addDataSource("className", className); workbook.addDataSource("s", studentInfos); //Invoke to process the template workbook.processTemplate(); //save to an excel file workbook.save("Variable.xlsx");
//create a new workbook var workbook = Workbook() //Load template file Template_StudentInfo.xlsx from resource val templateFile = this.getResourceStream("xlsx/Template_StudentInfo.xlsx") workbook.open(templateFile) ///#region Define custom classes //class StudentInfo { // var name: String? = null // var address: String? = null // var family: ArrayList? = null //} ///#region Init Data val studentInfos = ArrayList() val student1 = StudentInfo() student1.name = "Jane" student1.address = "101, Halford Avenue, Fremont, CA" studentInfos.add(student1) val student2 = StudentInfo() student2.name = "Mark" student2.address = "2005 Klamath Ave APT, Santa Clara, CA" studentInfos.add(student2) val student3 = StudentInfo() student3.name = "Carol" student3.address = "1063 E EI Camino Real, Sunnyvale, CA 94087, USA" studentInfos.add(student3) val student4 = StudentInfo() student4.name = "Liano" student4.address = "1977 St Lawrence Dr, Santa Clara, CA 95051, USA" studentInfos.add(student4) val student5 = StudentInfo() student5.name = "Hellen" student5.address = "3661 Peacock Ct, Santa Clara, CA 95051, USA" studentInfos.add(student5) val className = "Class 3" ///#endregion //Add data source workbook.addDataSource("className", className) workbook.addDataSource("s", studentInfos) //Invoke to process the template workbook.processTemplate() //save to an excel file workbook.save("Variable.xlsx")