Page tree

Versions Compared

Key

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

...

You can create an ExcelWriter template in Microsoft Excel or in script using the ExcelApplication object. Include data markers where you want to insert values. For example, if cell B6 contains the data marker %%=Orders.OrderID, where Orders represents the Orders table in a database, ExcelWriter will import the OrderID column to column B in the spreadsheet.

Template

Image Removed

Spreadsheet generated from template

Image Modified

Image Added

A data marker binds in script to a data source which may be an array, DataTable, DataSet, or DataReader, and may include modifiers. Data source and field numbers are 1-based. If ExcelWriter encounters %%=#0[.field] or %%=[DataSource.]#0, an error will occur.

...

  1. Call ExcelTemplate.Process to populate the template's data markers with data source values:
    Code Block
    c#
    languagec#csharp
    xlt.Process();
    
    The Process method enters data source values in the template's merge fields, and creates the output file (the new spreadsheet) in memory.
    # Call ExcelTemplate.Save to generate a new spreadsheet:
    Code Block
    c#
    c#
    xlt.Save(Page.Response, "StringBinding.xls", false);
    
    If you pass Save a Page.Response object, ExcelWriter will stream the generated file to the client. Save's second parameter specifies a name for the generated Excel file; this name will be displayed in the download dialog when the file is streamed to the browser. If the third parameter is set to true and the user chooses to open the file, the file will open in the browser window; if it is set to false (as in the example) and the user chooses to open the file, the file will open in Microsoft Excel.
    \ExcelWriter allows you to save the generated file on the server or stream it to the client. For more information, see Output Options.