Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Table of Contents

Hello World with WordTemplate

WordWriter's WordTemplate approach allows you to write data to a template file that contains merge field. The merge fields tell WordWriter where to bind specific sets of data, similar to Word's mail merge. This tutorial will show you the basics on how to dynamically insert data into a document using WordTemplate by taking custom text from a web form textbox and inserting it into a template file.

Setting up the template file

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

Icon

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.

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>> which will correspond to a column in a data set with only one row of data.

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

Writing the code

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

Final Code

Downloads

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

  • []
  • []
  • No labels