//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); //Load template file Template_StudentInfo.xlsx from resource var templateFile = this.GetResourceStream("xlsx\\Template_StudentInfo.xlsx"); workbook.Open(templateFile); #region Define custom classes //public class StudentInfo //{ // public string name; // public string address; // public List<Family> family; //} #endregion #region Init Data var studentInfos = new List<StudentInfo> { new StudentInfo { name = "Jane", address = "101, Halford Avenue, Fremont, CA" }, new StudentInfo { name = "Mark", address = "2005 Klamath Ave APT, Santa Clara, CA" }, new StudentInfo { name = "Carol", address = "1063 E EI Camino Real, Sunnyvale, CA 94087, USA" }, new StudentInfo { name = "Liano", address = "1977 St Lawrence Dr, Santa Clara, CA 95051, USA" }, new StudentInfo { name = "Hellen", address = "3661 Peacock Ct, Santa Clara, CA 95051, USA" } }; var 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 Dim workbook As New Workbook 'Load template file Template_StudentInfo.xlsx from resource Dim templateFile = GetResourceStream("xlsx\Template_StudentInfo.xlsx") workbook.Open(templateFile) #Region "Define custom classes" 'Public Class StudentInfo ' Public name As String ' Public address As String ' Public family As List(Of Family) 'End Class #End Region #Region "Init Data" Dim studentInfos As New List(Of StudentInfo) From { New StudentInfo With { .name = "Jane", .address = "101, Halford Avenue, Fremont, CA" }, New StudentInfo With { .name = "Mark", .address = "2005 Klamath Ave APT, Santa Clara, CA" }, New StudentInfo With { .name = "Carol", .address = "1063 E EI Camino Real, Sunnyvale, CA 94087, USA" }, New StudentInfo With { .name = "Liano", .address = "1977 St Lawrence Dr, Santa Clara, CA 95051, USA" }, New StudentInfo With { .name = "Hellen", .address = "3661 Peacock Ct, Santa Clara, CA 95051, USA" } } Dim className = "Class 3" #End Region '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")