RR
Ramya R
Syncfusion Team
July 24, 2007 12:17 PM UTC
Hi Tim,
Thank you for your interest in Syncfusion Products.
This sample shows how the TemplateMarkers created by the enduser can be replaced with data at the runtime.
The basic idea is that the template will have markers like %Customers.ContactName inside cells and when we provide the data source (customers DataTable) , the contents of ContactName column will get inserted into the template document. For example, the end user of an application can format a template like he wants and then put the markers inside as specified and then have the data from the DataTable exported with the desired look.
There could be several arguments after variable they are delimited by some character (by default it is ; character)
Possible arguments:
--------------------
1) horizontal or vertical - specifies direction of the data import for complex variables (arrays, collections, data tables, etc.), vertical is default value.
2) insert - specifies that new row or column (depends on direction argument) for each new cell.
3) insert:copystyles - the same but also copies style from the above row or left column
4) jump: - specifies position of the next cell. This argument also can be appended by ":copystyles" then style of the single cell will be copied.
5) copyrange:: - copies specified cells after each cell import. Aslo can be appended by ":copystyles". There can be more than one copyrange argument for single template marker.
The TemplateMarkers sample does the following,
1. Opens the TemplateMarker xls file created by the end user. For this sample the TemplateMarker.xls file is placed in the location "Syncfusion\EssentialStudio\5.1.0.51\Windows\XlsIO.Windows\Samples\2.0\Data"
2. Replaces each TemplateMarker in that file with desired data using the code snippet below,
ITemplateMarkersProcessor marker = workbook.CreateTemplateMarkersProcessor();
marker.AddVariable("Customers",northwindDt);
//Insert Array Horizontally
string[] names = new string[]{"Mickey","Donald","Tom","Jerry"};
string[] descriptions = new string[]{"Mouse","Duck","Cat","Mouse"};
marker.AddVariable("Names",names);
marker.AddVariable("Descriptions",descriptions);
//Stretch Formula
marker.AddVariable("NumbersTable",numbersDt);
3. Processes the markers in the template using the code snippet below,
marker.ApplyMarkers();
4. Saves the workbook with these changes.
Please let me know if you have any queries.
Thanks & Regards,
Ramya.