Page tree

Versions Compared

Key

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

...

Note
iconfalse
titleRequirements

This sample requires OfficeWriter Enterprise Edition to be installed because the OfficeWriter Grouping and Nesting is only available in the Enterprise Edition of the product.

Note

Code

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 = @"..\..\templates\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(@"..\..\Output\StringDataSource_output.xlsx");
        }
    }

...