Intro

Data markers have multiple switches and options that are available for use in ExcelTemplate workbooks.

ExcelTemplate Grouping and Nesting allows users to bind flat data to a specially formatted spreadsheet with the data being displayed in a grouped or nested format. To learn how to create a template for Grouping and Nesting, see our in-depth tutorai Using Grouping and Nesting with ExcelTemplate.

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.

Code

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");
        }
    }

\

Downloads

Template: GroupingandNestingTemplate.xlsx

Output: GroupingandNesting_output.xlsx