//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); //Load template file from resource var templateFile = this.GetResourceStream("xlsx\\Template_SalesTracker.xlsx"); workbook.Open(templateFile); #region Init Data var datasource = new DataTable(); datasource.Columns.Add(new DataColumn("ProductName", typeof(string))); datasource.Columns.Add(new DataColumn("CostPerItem", typeof(double))); datasource.Columns.Add(new DataColumn("PercentMarkup", typeof(double))); datasource.Columns.Add(new DataColumn("TotalSold", typeof(Int32))); datasource.Columns.Add(new DataColumn("ShippingCharge", typeof(Int32))); datasource.Columns.Add(new DataColumn("ShippingCost", typeof(double))); datasource.Columns.Add(new DataColumn("Returns", typeof(Int32))); datasource.Rows.Add("Beverages", 10, 1, 15, 10, 5.75, 2); datasource.Rows.Add("Condiments", 11.5, 0.75, 18, 10, 5.75, 1); datasource.Rows.Add("Dairy Products", 13, 0.65, 20, 10, 6.25, 0); datasource.Rows.Add("Confections", 5, 0.9, 50, 5, 3.5, 0); datasource.Rows.Add("Sea Food", 4, 0.9, 42, 5, 3.25, 3); #endregion //Init template global settings workbook.Names.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("SalesTracker.xlsx");
' Create a new Workbook Dim workbook As New Workbook 'Load template file from resource Dim templateFile = GetResourceStream("xlsx\Template_SalesTracker.xlsx") workbook.Open(templateFile) #Region "Init Data" Dim datasource As New DataTable With datasource.Columns .Add(New DataColumn("ProductName", GetType(String))) .Add(New DataColumn("CostPerItem", GetType(Double))) .Add(New DataColumn("PercentMarkup", GetType(Double))) .Add(New DataColumn("TotalSold", GetType(Integer))) .Add(New DataColumn("ShippingCharge", GetType(Integer))) .Add(New DataColumn("ShippingCost", GetType(Double))) .Add(New DataColumn("Returns", GetType(Integer))) End With With datasource.Rows .Add("Beverages", 10, 1, 15, 10, 5.75, 2) .Add("Condiments", 11.5, 0.75, 18, 10, 5.75, 1) .Add("Dairy Products", 13, 0.65, 20, 10, 6.25, 0) .Add("Confections", 5, 0.9, 50, 5, 3.5, 0) .Add("Sea Food", 4, 0.9, 42, 5, 3.25, 3) End With #End Region 'Init template global settings workbook.Names.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("SalesTracker.xlsx")