Page tree

Versions Compared

Key

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

Intro

Excerpt

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

Data Markers can have optional modifiers that change the way the data is imported to or displayed on a report. 

The Data Marker Options used in this example are:           

  • Fieldname, which imports the name of the field

...

  • Uppercase, which forces characters to uppercase

...

  • Lowercase, which forces characters to lowercase

...

  • Preserve, which forces number strings to be treated as text

...

  • Optional, this will cause the data marker's place to be left empty if it is unbound

Download the template and the report to see how the Data Marker Options in the template change the way that the data in the report is presented.

Code

Code Block

Insert code here

Downloads

...

Code

Code Block
public class DataMarkerOptions
    {
 
        /// <summary>
        /// Build the report with ExcelTemplate
        /// </summary>
        public void GenerateReport()
        {
              // This 2D Object[][] array will hold the values to be imported

              object[,] values = {
                              //employee ID 
                              {1, 2, 3, 4},
                              //Last Name   
                              {"Davolio", "Fuller", "Leverling", "Peacock"},
                              //First Name 
                              {"Nancy", "Andrew", "Janet", "Margaret"},
                              //Title
                              {"Sales Rep", "VP of Sales", "Sales Rep", "Sales Rep"},
                              //Zip         
                              {"02139","02144","23451","00213"}
                            };

 
            // These are the field names
            string[] colnames = { "EmployeeID", "LastName", "FirstName", "Title", "Zip" };
 
            // Create an instance of ExcelTemplate
            ExcelTemplate xlt = new ExcelTemplate();
 
            // Open the template workbook
                        string templatePath = @"..\..\ExcelTemplateFiles\DataMarkerOptionsTemplate.xlsx";

            xlt.Open(templatePath);
 
            // Pass colnames and values arrays to BindData()
            DataBindingProperties bindingProperties = xlt.CreateDataBindingProperties();
            bindingProperties.MaxRows = ExcelTemplate.ALL_ROWS;
            bindingProperties.Transpose = true;
            xlt.BindData(values, colnames, "dSource", bindingProperties);
 
            // Call the process() method to populate the template with the data source values
            xlt.Process();
 
            // Save the report
            xlt.Save(@"..\..\ExcelOutputFiles\DataMarkerOptions_output.xlsx");
         }
    }

Downloads