Page tree
Skip to end of metadata
Go to start of metadata

Passing ExcelApplication to ExcelTemplate

ExcelWriter allows you to generate a spreadsheet from script alone - using the ExcelApplication object - or from a template spreadsheet and a script, using ExcelTemplate. You can also use ExcelApplication and ExcelTemplate together. This section shows you how to generate a template spreadsheet with ExcelApplication and pass the spreadsheet to ExcelTemplate which then populates the template's data markers.

  1. Use ExcelApplication to create a worksheet and enter data marker strings in the worksheet's cells:
    A data marker is a cell value beginning with %%= or %%=$ that specifies a variable, an array, or a database column, to insert in the spreadsheet column containing the marker. The data marker may be followed by a modifier. For example, to include column headers in the populated data marker column, the data marker should include the (fieldname) modifier:
    For more information, see Creating Data Markers.

  2. To open the workbook you created as an ExcelTemplate, pass your ExcelApplication and Workbook objects to ExcelTemplate's Open method:
  3. Connect to a database and execute a query to return a DataTable, DataView, or DataReader to use a data source for template data markers, for example:
    Alternatively, the data source for the template may be a rectangular array.

  4. Set the returned DataTable, DataView, or DataReader as the data source for template data markers, and call Process to populate the data markers with data source values:
  5. Call Save to save the template on the server, return it in memory, or - as in the following example - stream it to the browser:

Example

Code Sample: Passing ExcelApplication to ExcelTemplate

[C#] | [VB.NET]

  • No labels