//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); // Load template file workbook.Open(this.GetResourceStream("xlsx\\Template_ProductLabel.xlsx")); // Init Data #region Init Data var datasource = new DataTable(); datasource.Columns.Add(new DataColumn("ProductCode", typeof(string))); datasource.Columns.Add(new DataColumn("Brand", typeof(string))); datasource.Columns.Add(new DataColumn("Category", typeof(string))); datasource.Columns.Add(new DataColumn("Description", typeof(string))); datasource.Columns.Add(new DataColumn("Price", typeof(double))); datasource.Rows.Add("BSE0050", "Bose", "Consumer Electronics", "Bose 785593-0050", 928.00); datasource.Rows.Add("BSE0250", "Bose", "Consumer Electronics", "Bose 785593-0250", 828.00); datasource.Rows.Add("BSE0110", "Bose", "Consumer Electronics", "Bose 785593-0110", 195.50); datasource.Rows.Add("CNNE00B", "Canon", "Consumer Electronics", "Canon EOS 1500B", 986.50); datasource.Rows.Add("CNNP00D", "Canon", "Consumer Electronics", "Canon POS 1500D", 891.10); datasource.Rows.Add("CNNV00C", "Canon", "Consumer Electronics", "Canon VOS 1500C", 459.00); datasource.Rows.Add("HAR394L", "Haier", "Consumer Electronics", "Haier 394L 4Star", 367.05); datasource.Rows.Add("HAR364L", "Haier", "Consumer Electronics", "Haier 364L 4Star", 729.10); datasource.Rows.Add("HAR356L", "Haier", "Consumer Electronics", "Haier 356L 4Star", 578.90); datasource.Rows.Add("IFBFA65", "IFB", "Consumer Electronics", "IFB 6.5 FullyAuto", 904.90); datasource.Rows.Add("IFBFA75", "IFB", "Consumer Electronics", "IFB 7.5 FullyAuto", 673.80); datasource.Rows.Add("IFBFA80", "IFB", "Consumer Electronics", "IFB 8.0 FullyAuto", 829.10); datasource.Rows.Add("MiLED40", "Mi", "Consumer Electronics", "Mi LED 40inch", 550.10); datasource.Rows.Add("MiLED55", "Mi", "Consumer Electronics", "Mi LED 55inch", 178.02); datasource.Rows.Add("MiLED60", "Mi", "Consumer Electronics", "Mi LED 60inch", 102.95); datasource.Rows.Add("SAN40BT", "Sennheiser", "Consumer Electronics", "Sennheiser 4.40-BT", 171.00); datasource.Rows.Add("SAN50BT", "Sennheiser", "Consumer Electronics", "Sennheiser 4.50-BT", 234.59); datasource.Rows.Add("IPHN0XR", "Iphone", "Mobile", "Iphone XR", 173.21); datasource.Rows.Add("IPHN0XS", "Iphone", "Mobile", "Iphone XS", 109.00); datasource.Rows.Add("1PLS07P", "OnePlus", "Mobile", "OnePlus 7Pro", 491.00); datasource.Rows.Add("1PLS08P", "OnePlus", "Mobile", "OnePlus 8Pro", 210.00); datasource.Rows.Add("RDMI007", "Redmi", "Mobile", "Redmi 7", 816.50); datasource.Rows.Add("RDMI008", "Redmi", "Mobile", "Redmi 8", 273.90); datasource.Rows.Add("SMSG0S9", "Samsung", "Mobile", "Samsung S9", 892.50); datasource.Rows.Add("SMSGS10", "Samsung", "Mobile", "Samsung S10", 992.50); datasource.Rows.Add("SMSG0S8", "Samsung", "Mobile", "Samsung S8", 715.20); datasource.Columns.Add("Barcode", typeof(string)); foreach (DataRow row in datasource.Rows) { row["Barcode"] = row["ProductCode"].ToString() + row["Price"].ToString(); } #endregion workbook.Names.Add("TemplateOptions.KeepLineSize", "true"); //Add data source workbook.AddDataSource("ds", datasource); //Invoke to process the template workbook.ProcessTemplate(); // Save to a pdf file workbook.Save("ProductLabel.pdf");
' Create a new Workbook Dim workbook As New Workbook ' Load template file workbook.Open(Me.GetResourceStream("xlsx\Template_ProductLabel.xlsx")) ' Init Data #Region "Init Data" Dim datasource = New DataTable() datasource.Columns.Add(New DataColumn("ProductCode", GetType(String))) datasource.Columns.Add(New DataColumn("Brand", GetType(String))) datasource.Columns.Add(New DataColumn("Category", GetType(String))) datasource.Columns.Add(New DataColumn("Description", GetType(String))) datasource.Columns.Add(New DataColumn("Price", GetType(Double))) datasource.Rows.Add("BSE0050", "Bose", "Consumer Electronics", "Bose 785593-0050", 928.0) datasource.Rows.Add("BSE0250", "Bose", "Consumer Electronics", "Bose 785593-0250", 828.0) datasource.Rows.Add("BSE0110", "Bose", "Consumer Electronics", "Bose 785593-0110", 195.5) datasource.Rows.Add("CNNE00B", "Canon", "Consumer Electronics", "Canon EOS 1500B", 986.5) datasource.Rows.Add("CNNP00D", "Canon", "Consumer Electronics", "Canon POS 1500D", 891.1) datasource.Rows.Add("CNNV00C", "Canon", "Consumer Electronics", "Canon VOS 1500C", 459.0) datasource.Rows.Add("HAR394L", "Haier", "Consumer Electronics", "Haier 394L 4Star", 367.05) datasource.Rows.Add("HAR364L", "Haier", "Consumer Electronics", "Haier 364L 4Star", 729.1) datasource.Rows.Add("HAR356L", "Haier", "Consumer Electronics", "Haier 356L 4Star", 578.9) datasource.Rows.Add("IFBFA65", "IFB", "Consumer Electronics", "IFB 6.5 FullyAuto", 904.9) datasource.Rows.Add("IFBFA75", "IFB", "Consumer Electronics", "IFB 7.5 FullyAuto", 673.8) datasource.Rows.Add("IFBFA80", "IFB", "Consumer Electronics", "IFB 8.0 FullyAuto", 829.1) datasource.Rows.Add("MiLED40", "Mi", "Consumer Electronics", "Mi LED 40inch", 550.1) datasource.Rows.Add("MiLED55", "Mi", "Consumer Electronics", "Mi LED 55inch", 178.02) datasource.Rows.Add("MiLED60", "Mi", "Consumer Electronics", "Mi LED 60inch", 102.95) datasource.Rows.Add("SAN40BT", "Sennheiser", "Consumer Electronics", "Sennheiser 4.40-BT", 171.0) datasource.Rows.Add("SAN50BT", "Sennheiser", "Consumer Electronics", "Sennheiser 4.50-BT", 234.59) datasource.Rows.Add("IPHN0XR", "Iphone", "Mobile", "Iphone XR", 173.21) datasource.Rows.Add("IPHN0XS", "Iphone", "Mobile", "Iphone XS", 109.0) datasource.Rows.Add("1PLS07P", "OnePlus", "Mobile", "OnePlus 7Pro", 491.0) datasource.Rows.Add("1PLS08P", "OnePlus", "Mobile", "OnePlus 8Pro", 210.0) datasource.Rows.Add("RDMI007", "Redmi", "Mobile", "Redmi 7", 816.5) datasource.Rows.Add("RDMI008", "Redmi", "Mobile", "Redmi 8", 273.9) datasource.Rows.Add("SMSG0S9", "Samsung", "Mobile", "Samsung S9", 892.5) datasource.Rows.Add("SMSGS10", "Samsung", "Mobile", "Samsung S10", 992.5) datasource.Rows.Add("SMSG0S8", "Samsung", "Mobile", "Samsung S8", 715.2) datasource.Columns.Add("Barcode", GetType(String)) For Each row As DataRow In datasource.Rows row("Barcode") = row("ProductCode").ToString() & row("Price").ToString() Next row #End Region workbook.Names.Add("TemplateOptions.KeepLineSize", "true") 'Add data source workbook.AddDataSource("ds", datasource) 'Invoke to process the template workbook.ProcessTemplate() ' save to a pdf file workbook.Save("ProductLabel.pdf")