Table of Contents |
---|
OfficeWriter's WordTemplate object opens a WordWriter template file, populates it with data from one or more data sources, and generates a new Word file. A WordWriter template is a file created in Microsoft Word that contains merge fields. A merge field displays a data source field name (for example, a database column name) where a data source value will be inserted. Merge fields are bound to a data source in OfficeWriter code. When you run the code, OfficeWriter replaces the merge fields with values from the data source and creates a new Word file.
WordTemplate's SetDataSource method binds the merge fields to a data source, which may be an array or a database table record. The Process method enters values from the data source in the template's merge fields.
To create a merge field:
The Field Dialog in Microsoft Word 2002 (XP)
A repeat block is a text fragment, a list, or a table row in the template document, defined by a Word bookmark, that contains merge fields. In the WordWriter code, a data source is assigned to each repeat block. Repeat blocks allow you to:
To create a repeat block:
In Microsoft Word, bookmarks are not marked by default. To see which document fragments are bookmarks:
Bookmarks are marked by grey brackets:
The Main Document and Repeat Blocks\ A WordWriter template may include merge fields in repeat blocks, merge fields in the main document, or both. The "main document" is any part of the template that is not within a repeat block. Merge fields within the main document are bound to a data source by the method SetDataSource. Merge fields within repeat blocks are bound to a data source by the method SetRepeatBlock. |
Not all Word features can be included in a repeat block:
Supported in Repeat Blocks |
Not Supported in Repeat Blocks |
---|---|
|
|
A mail merge is a text fragment, a list, or a table row in the template document that contains merge fields. Unlike repeat blocks, a bookmark is not needed to define the fragment to be repeated. The entire page is treated as a repeat block and repeated as the document is filled with data. The NEXT field can optionally be used to tell WordWriter to move to the next row of data between identical merge fields. Mail merges allow you to import multiple rows from a data source without defining a repeat block.
To create a mail merge:
Not all Word features can be included in a Mail Merge:
Supported in Mail Merges |
Not Supported in Mail Merges |
---|---|
|
|
WordWriter cannot process "fast saved" Word files. Fast saving is a Microsoft Word feature that makes file saving faster by saving only document modifications. When you create a WordWriter template, make sure that fast saves are turned off:
WordWriter populates merge fields with values from an array or a database. When you use a database as the template's data source, you can use Word's MailMerge toolbar to connect to the database, and select merge fields names from a list of available database fields:
The following VB.NET and C# samples use WordWriter to open an envelope template, set a data source, populate the merge fields, and generate a new envelope. The envelope template contains merge fields for the delivery name and address, and the return name and address. The WordWriter code uses an array as the data source and gets the array values from an HTML form. To run the sample, click Run Sample, enter return and delivery information in the form, and click the Generate button.
[C#] | [VB.NET]
To create an envelope template:
The following VB.NET and C# samples use WordWriter to open a fax cover template, set a data source, populate the merge fields, and generate a new fax cover document. The template contains the merge fields ToName, FromName, FaxNumber, PhoneNumber, Subject, PageCount, Comments, chkUrgent, chkReview, and chkComment. The WordWriter code uses an array as the data source and gets the array values from an HTML form.
Check boxes in the HTML form provide the values for chkUrgent, chkReview, and chkComment. If a box is checked, "X" will be entered in the data source value array and displayed in the generated file. If a box is not checked, an empty string will be entered in the value array and nothing will be displayed by the field name (for example, by "Urgent") in the generated file. To run the sample, click Run Sample, enter the fax information in the form, and click the Generate button.
[C#] | [VB.NET]
To create a fax cover template using one of Microsoft Word's available templates:
The following VB.NET and C# samples use WordWriter to open a template form letter, set a data source, populate the merge fields, and generate a new file. The template form letter contains merge fields for recipient name and address and author name and title. The WordWriter code uses an array as the data source and gets the array values from an HTML form. To run the sample, click Run Sample, enter recipient and author information in the form, and click the Generate button.