Creating a WordWriter Template



Creating a Merge Field

A 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.

  1. In Microsoft Word, open or create a document to use as your WordWriter template.

  2. From the Insert menu, select Field... to open the Field dialog.

  3. From the Field names list, select MergeField.

  4. In the Field name text box, enter a name for the merge field. For example, enter ProductName.

  5. Optional: From the Format list, select a display format.

  6. Optional: In Field Options, check Text to be inserted before and enter text to insert before the merge field.

  7. Optional: In Field Options, check Text to be inserted after and enter text to insert after the merge field.

    WordWriter 1.0 does not support the following formatting options: Mapped field and Vertical formatting.

The Field Dialog in Microsoft Word 2002 (XP)

Top
Using an ODBC Data Source to Create Merge Fields

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:

  1. In Microsoft Word, open or create a document to use as your WordWriter template.

  2. From the View menu, select Toolbars -> Mail Merge.

  3. Click the Open Data Source icon.

    Open Data Source

  4. Select a database. For example, open the Access database Northwind.mdb, located in WordWriter\doc-samples\samples\database.

  5. Select a database table from the list.

  6. Click the Insert Merge Fields icon.

    Insert Merge Fields

  7. From the Fields list, select a field (a column name) and click Insert. Repeat to add additional fields to the template.


  8. To format a merge field, right-click the merge field and select Edit field... to open the Field dialog. For more information about the Field dialog, see Creating a Merge Field.
Top
Example: Creating a Template Envelope

The 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.

VB.NET Example
Intermediate/Envelope/Envelope-vb.aspx

[View Source]
C# Example
Intermediate/Envelope/Envelope-cs.aspx

[View Source]

To create a template envelope:

  1. Open Microsoft Word.

  2. To display the Mail Merge toolbar, open the View menu and select Toolbars -> Mail Merge.

  3. Click the Main document setup icon.

    Main document setup

  4. Select Envelopes.



  5. In the Envelope Options dialog, select envelope size, address fonts, and printing options.

  6. Within the main document (the envelope), in the delivery and return address boxes, enter merge fields. For instructions, see Creating a Merge Field.
Top
Example: A Fax Cover 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.

VB.NET Example
Intermediate/FaxCover/FaxCover-vb.aspx

[View Source]
C# Example
Intermediate/FaxCover/FaxCover-cs.aspx

[View Source]

To create a fax cover template using one of Microsoft Word's available templates:

  1. In Microsoft Word, open the File menu, and select New...


  2. From the New Document window, select General Templates...


  3. In the Templates dialog, select the Letters & Faxes tab.


  4. Select one of the available fax templates.


  5. Insert merge fields in the template.


Top
Example: A Form Letter Template

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.

VB.NET Example
Intermediate/FormLetter/FormLetter-vb.aspx

[View Source]
C# Example
Intermediate/FormLetter/FormLetter-cs.aspx

[View Source]

Top


Copyright © 2003, SoftArtisans, Inc.