Table of Contents |
---|
Getting Started
About templates and merge fields
A WordWriter template is a Microsoft Word file that contains merge fields. A merge field displays a data source field (for example, a database column name). A merge field is created in Microsoft Word and bound in code to a data source. The data source may be an array, a DataSet, a DataTable, or a DataReader. When you run the code, WordWriter populates the merge fields with data source values. A template may contain multiple sets of merge fields. Each set of fields binds to a single data source.
Merge field syntax
- The general syntax is: DataSource.ColumnName
- Ordinal syntax (i.e. #1.#2 for source one, column two) can also be used
- Data source and column names must not include Unicode characters.
- Data source and column names must begin with a letter (A-Z, a-z).
- Data source and column names may include the following characters only:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_ - Spaces are not allowed anywhere in a merge field.
Setting up the Template
Adding merge fields
The final template will resemble this:
1. Start with a blank .docx file.
2. Add the merge fields for the header data. These values are a single row of data called "Header." The values are "FirstName," "LastName," and "Date."
3. Create a table for the order data and add the merge fields. These values are in a data table created from AdventureWorks data. In this sample, the values are "Item," "Qty," "Price," "LineTotal," "SubTotal," "Tax," and "Total."
The template should resemble this:
4. The template can be styled as desired. Any formatting applied to a merge field will be persisted when WordWriter populates the data.
Adding a WordWriter Reference in Visual Studio
Create a .NET project and add a reference to the WordWriter library.
- Open Visual Studio and create a .NET project.
- The sample code uses a web application.
- Add a reference to SoftArtisans.OfficeWriter.WordWriter.dll
- SoftArtisans.OfficeWriter.WordWriter.dll is located under Program Files > SoftArtisans > OfficeWriter > dotnet > bin