Passing ExcelTemplate to ExcelApplication
ExcelWriter allows you to generate a spreadsheet from script alone - using the
ExcelApplication
object - or from a template spreadsheet and a script, using
ExcelTemplate.
ExcelTemplate provides an intuitive high-performance way
to import database values to a spreadsheet, but cannot otherwise modify a spreadsheet at
runtime. ExcelApplication's rich object model allows you to modify every aspect
of the spreadsheet at runtime. You can take advantage of the features of both
ExcelApplication and ExcelTemplate by using them
together. For example, you can use ExcelTemplate to open and
populate an ExcelWriter template, then pass the populated workbook to
ExcelApplication and add a chart.
To pass a workbook from ExcelTemplate to ExcelApplication,
do not call ExcelTemplate.Save. Instead, pass the ExcelTemplate
object to ExcelApplication's Open method:
ExcelTemplate xlt = new ExcelTemplate();
xlt.Open(templatePath);
...
xlt.SetDataSource(data, "Sales");
xlt.Process();
/* Create an instance of ExcelApplication and
* open the spreadsheet you created with ExcelTemplate.
* The spreadsheet will be returned as a Workbook
* object.
*/
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Open(xlt);
...
Code Sample: Passing ExcelTemplate to ExcelApplication


Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.
|