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.
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.
C# | Visual Basic |
---|---|
Program.cs | Program.vb |
ImageStreamProvider.cs | ImageStreamProvider.vb |
- How to Use DOCVARIABLE Fields in a Document
- How to: Embed Images into a Mail Merge Template
- How to: Send a Mail-Merge Document as an E-mail
- How to: Import HTML Files that Contain Images Referenced with a Custom Prefix
- Mail Merge in Word Processing Document API
- How to: Insert Dynamic Content
- How to: Replace a Placeholder with a Document Element
(you will be redirected to DevExpress.com to submit your response)