//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); //Load template file from resource var templateFile = this.GetResourceStream("xlsx\\Template_ConstructionProposal.xlsx"); workbook.Open(templateFile); #region Init Data var datasource = new DataTable(); datasource.Columns.Add(new DataColumn("QUANTITY", typeof(Int32))); datasource.Columns.Add(new DataColumn("DESCRIPTION", typeof(string))); datasource.Columns.Add(new DataColumn("UNIT PRICE", typeof(Double))); datasource.Rows.Add(10, "Item 1", 165); datasource.Rows.Add(21, "Item 2", 40); datasource.Rows.Add(5, "Item 3", 10.5); datasource.Rows.Add(164, "Item 4", 2.75); datasource.Rows.Add(6, "Item 5", 12); datasource.Rows.Add(18, "Item 6", 5.5); datasource.Rows.Add(1, "Item 7", 25); #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();
' Create a new Workbook Dim workbook As New Workbook 'Load template file from resource Dim templateFile = GetResourceStream("xlsx\Template_ConstructionProposal.xlsx") workbook.Open(templateFile) #Region "Init Data" Dim datasource As New DataTable With datasource.Columns .Add(New DataColumn("QUANTITY", GetType(Integer))) .Add(New DataColumn("DESCRIPTION", GetType(String))) .Add(New DataColumn("UNIT PRICE", GetType(Double))) End With With datasource.Rows .Add(10, "Item 1", 165) .Add(21, "Item 2", 40) .Add(5, "Item 3", 10.5) .Add(164, "Item 4", 2.75) .Add(6, "Item 5", 12) .Add(18, "Item 6", 5.5) .Add(1, "Item 7", 25) 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("ConstructionProposal.xlsx")