Migrating ExcelTemplate
Applications
from Interop
to Pure .NET
|
 |
|
In previous versions of OfficeWriter for Excel, .NET
support was added through the introduction of Interop
assemblies. These Interop assemblies facilitated communication
between .NET applications and the COM version of OfficeWriter.
|
|
In OfficeWriter v3, .NET support has been further improved
with the introduction of the SAXW5NET.dll assembly, which provides
a pure .NET ExcelTemplate object. To migrate your existing
Interop-based OfficeWriter application to use the new pure
.NET ExcelTemplate object
there are four main areas where you will need to make modifications:
1. OfficeWriter for Excel Namespace
and Application References
| Old Namespace Import: |
New Namespace Import: |
[C#]
using
SoftArtisans.ExcelWriter;
[VB.NET]
Imports
SoftArtisans.ExcelWriter |
[C#]
using
SoftArtisans.OfficeWriter.ExcelWriter;
[VB.NET]
Imports
SoftArtisans.Officewriter.ExcelWriter |
|
| Old Object Instantiation: |
New Object Instantiation: |
[C#]
SAExcelTemplateDotNet
oXlw
= new SAExcelTemplateDotNet();
[VB.NET]
Dim
oXlw As New SAExcelTemplateDotNet() |
[C#]
ExcelTemplate
oXlw
= new ExcelTemplate();
[VB.NET]
Dim
oXlw As New SAExcelTemplate () |
|
2. Setting Data Sources
With the pure .NET ExcelTemplate object,
the setting of data sources has changed to accommodate more
native .NET types. The most significant change is that you
can now use ADO.NET DataTables and DataReaders as data sources
(in addition to DataSets). In the previous version you needed
to pass in the DataSet that contained the DataTable. Now
you can just pass in the DataTable to one of the overloaded SetDataSource methods.
The new .NET ExcelTemplate also
includes many new methods for setting array data sources
(1-dimensional and 2-dimensional).
3. Template Processing and Saving
To process and save a spreadsheet with the Interop version
of ExcelTemplate,
a single call to Process was
required. In the .NET ExcelTemplate,
a call to Process and
a call to Save are
required. This second approach allows you to save more than
one copy of a generated file, and/or both save the file on
the server and stream it to the client. Using multiple Process and Save calls,
you can generate multiple files from a single template and
an updated data source.
4. Data Marker Syntax
Most of your existing templates should still work with the
pure .NET ExcelTemplate object.
However, there are two things to be aware of:
- The data markers must be comprised of the characters
and/or numbers: a-z, A-Z, and 0-9.
- The dollar sign ($) is no longer necessary in
all non-database data markers. This makes it easier for
developers to use mock data in arrays during development;
when the report is deployed to use a database, the data
markers will not have to be changed. The $ is now only
required when binding to a single object or single columnar
array, where a field name or field ordinal is not specified
in the data marker.
Please Note: Your existing templates will still work,
if you leave the $ in place. This allows for the re-use of
templates created for the Interop ExcelTemplate object
without any modifications. |