Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public class StringDataSource
    {
        private string recipientName;
        private string recipientCompany;

        /// <summary>
        /// Build the report with ExcelTemplate
        /// </summary>
        public void GenerateReport()
        {

            this.recipientName = "Jon Smith";
            this.recipientCompany = "SoftArtisans";
            // Create an instance of SoftArtisans ExcelTemplate
            ExcelTemplate xlt = new ExcelTemplate();

            // Open the template workbook
                        string templatePath = @"..\..\templatesExcelTemplateFiles\StringDataSourceTemplate.xlsx";
            xlt.Open(templatePath);

            // Bind the variables to the template datamarkers
            // %%=$RecipientName

            xlt.BindCellData(recipientName, "RecipientName", xlt.CreateDataBindingProperties());

            // %%=$RecipientCompany
            xlt.BindCellData(recipientCompany, "RecipientCompany", xlt.CreateDataBindingProperties());

            // Process the template to populate it with the Data Source data
            xlt.Process();

            // Save the report by streaming to the client
            xlt.Save(@"..\..\OutputExcelOutputFiles\StringDataSource_output.xlsx");

        }
    }

 

Downloads