Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Setting up the template file

1. Create a new .DOCX file. Save it as template.docx.

Info

In the sample code, the completed template file is located in templates/template.docx

2. Go to the Insert tab on the ribbon > Text group > Quick Parts drop-down. Select Field.

Image Added

3. In the Field dialog, select Mergefield from the Field names list.

4. In the Field Properties section, type "Variable" in the Field name box. Click OK.

This will create a merge field <<Variable>>. <<Variable>> will correspond to a column in a data set with only one row of data.

Image Added

5. The template is now complete. We'll move on to writing the code to bind the data to this merge field.

Image Added

Writing the code

1. Include the SoftArtisans.OfficeWriter.WordWriter namespace in the code behind.

...

You can download the code for the hello world tutorial as a Visual Studio solution.