//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); //Load template file from resource var templateFile = this.GetResourceStream("xlsx\\Template_MedicalReport.xlsx"); workbook.Open(templateFile); #region Init Data var datasource = new DataTable(); datasource.Columns.Add(new DataColumn("Date", typeof(DateTime))); datasource.Columns.Add(new DataColumn("Time", typeof(TimeSpan))); datasource.Columns.Add(new DataColumn("Event", typeof(string))); datasource.Columns.Add(new DataColumn("Systolic", typeof(Int32))); datasource.Columns.Add(new DataColumn("Diastolic", typeof(Int32))); datasource.Columns.Add(new DataColumn("HeartRate", typeof(Int32))); datasource.Columns.Add(new DataColumn("Glucose", typeof(Int32))); datasource.Columns.Add(new DataColumn("Notes", typeof(string))); datasource.Rows.Add(DateTime.Today, new TimeSpan(6, 0, 0), "Wake", 129, 79, 72, 55, null); datasource.Rows.Add(DateTime.Today, new TimeSpan(7, 0, 0), "Before Meal", 120, 80, 74, 70, null); datasource.Rows.Add(DateTime.Today, new TimeSpan(9, 0, 0), "After Meal", 133, 80, 75, 75, null); datasource.Rows.Add(DateTime.Today, new TimeSpan(10, 0, 0), "BP only", 143, 91, 75, 190, null); datasource.Rows.Add(DateTime.Today, new TimeSpan(12, 0, 0), "Before Meal", 141, 84, 70, 140, null); datasource.Rows.Add(DateTime.Today, new TimeSpan(15, 0, 0), "After Meal", 132, 80, 68, 90, "Took BP medication with meal"); #endregion //Init template global settings workbook.Names.Add("TemplateOptions.KeepLineSize", "true"); workbook.Names.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");
' Create a new Workbook Dim workbook As New Workbook 'Load template file from resource Dim templateFile = GetResourceStream("xlsx\Template_MedicalReport.xlsx") workbook.Open(templateFile) #Region "Init Data" Dim datasource As New DataTable With datasource.Columns .Add(New DataColumn("Date", GetType(Date))) .Add(New DataColumn("Time", GetType(TimeSpan))) .Add(New DataColumn("Event", GetType(String))) .Add(New DataColumn("Systolic", GetType(Integer))) .Add(New DataColumn("Diastolic", GetType(Integer))) .Add(New DataColumn("HeartRate", GetType(Integer))) .Add(New DataColumn("Glucose", GetType(Integer))) .Add(New DataColumn("Notes", GetType(String))) End With With datasource.Rows datasource.Rows.Add(Date.Today, New TimeSpan(6, 0, 0), "Wake", 129, 79, 72, 55, Nothing) datasource.Rows.Add(Date.Today, New TimeSpan(7, 0, 0), "Before Meal", 120, 80, 74, 70, Nothing) datasource.Rows.Add(Date.Today, New TimeSpan(9, 0, 0), "After Meal", 133, 80, 75, 75, Nothing) datasource.Rows.Add(Date.Today, New TimeSpan(10, 0, 0), "BP only", 143, 91, 75, 190, Nothing) datasource.Rows.Add(Date.Today, New TimeSpan(12, 0, 0), "Before Meal", 141, 84, 70, 140, Nothing) datasource.Rows.Add(Date.Today, New TimeSpan(15, 0, 0), "After Meal", 132, 80, 68, 90, "Took BP medication with meal") End With #End Region 'Init template global settings workbook.Names.Add("TemplateOptions.KeepLineSize", "true") workbook.Names.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")