Skip to content

Use Word Processing Document API to generate a mail merge template, populate it with data, and export the result to a DOCX file.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/word-document-api-mail-merge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Word Processing Document API - How to Automate Mail Merge: Generate, Populate, and Export Documents

This sample project demonstrates how to use the mail merge feature to generate a template, populate it with data, and export the result to a DOCX file.

word processing document api mail merge result

Implementation Details

The RichEditDocumentServer.LoadDocument method call loads a document template. The AddMailMergeFields method implementation inserts the INCLUDEPICTURE and MERGEFIELD fields into the template's main body, and the INCLUDEPICTURE field to the footer.

The document template contains the DOCVARIABLE field that inserts the number of years the employee has worked at the company. The nested MERGEFIELD refers to the HireDate entry in the database. This field value is calculated in the CalculateDocumentVariable event handler.

The ImageStreamProvider class is used to insert images from a database. The GetStream method parses the received URI (the INCLUDEPICTURE field), finds the required data row, and returns the MemoryStream containing an image.

This project uses an XML file as the data source. The mail merge result is saved to the DOCX file.

Files to Review

C# Visual Basic
Program.cs Program.vb
ImageStreamProvider.cs ImageStreamProvider.vb

More Examples

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Use Word Processing Document API to generate a mail merge template, populate it with data, and export the result to a DOCX file.

Topics

Resources

License

Stars

Watchers

Forks