|
Creating a Merge FieldA WordWriter template is a Microsoft Word file that contains merge fields. A merge field displays a data source field name (for example, a database column name). WordWriter's SetDataSource method binds the merge fields to a data source, which may be an array or a database table record. WordWriter's Process method enters values from the data source in the template's merge fields.
Using an ODBC Data Source to Create Merge FieldsWordWriter 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:
Example: Creating a Template EnvelopeThe following VB.NET and C# samples use WordWriter to open a template envelope, set a data source, populate the merge fields, and generate a new envelope. The template envelope 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.
To create a template envelope:
Example: A Fax Cover TemplateThe 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.
To create a fax cover template using one of Microsoft Word's available templates:
Example: A Form Letter TemplateThe 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.
Copyright © 2003, SoftArtisans, Inc. |