Skip to content

create readme #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/vale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: vale-validation
on:
pull_request:
paths:
- README.md

jobs:
vale:
name: runner / vale
runs-on: ubuntu-latest
steps:
- name: clone repo
uses: actions/checkout@v4
- name: clone vale-styles repo
uses: actions/checkout@v4
with:
repository: DevExpress/vale-styles
path: vale-styles
ssh-key: ${{ secrets.VALE_STYLES_ACCESS_KEY }}
- name: copy vale rules to the root repo
run: shopt -s dotglob && cp -r ./vale-styles/vale/* .
- name: vale linter check
uses: DevExpress/vale-action@reviewdog
with:
files: README.md
fail_on_error: true
filter_mode: nofilter
reporter: github-check
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @DevExpressExampleBot
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- default badges list -->
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
<!-- default badges end -->
# 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](./media/image.png)

## Implementation Details

The [RichEditDocumentServer.LoadDocument](https://docs.devexpress.com/OfficeFileAPI/DevExpress.XtraRichEdit.RichEditDocumentServer.LoadDocument.overloads) 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](https://docs.devexpress.com/OfficeFileAPI/DevExpress.XtraRichEdit.RichEditDocumentServer.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](./CS/WordProcessingMailMerge/Program.cs) | [Program.vb](./VB/WordProcessingMailMerge/Program.vb) |
| [ImageStreamProvider.cs](./CS/WordProcessingMailMerge/ImageStreamProvider.cs) | [ImageStreamProvider.vb](./VB/WordProcessingMailMerge/ImageStreamProvider.vb) |

## More Examples

* [How to Use DOCVARIABLE Fields in a Document](https://github.com/DevExpress-Examples/word-document-api-use-docvariable-fields)
* [How to: Embed Images into a Mail Merge Template](https://github.com/DevExpress-Examples/how-to-use-images-in-richedit-mail-merge)
* [How to: Send a Mail-Merge Document as an E-mail](https://github.com/DevExpress-Examples/word-document-api-send-mail-merge-document-as-email)
* [How to: Import HTML Files that Contain Images Referenced with a Custom Prefix](https://github.com/DevExpress-Examples/how-to-import-html-files-that-contain-images-referenced-with-custom-prefix)

## Documentation

* [Mail Merge in Word Processing Document API](https://docs.devexpress.com/OfficeFileAPI/15277/word-processing-document-api/mail-merge)
* [How to: Insert Dynamic Content](https://docs.devexpress.com/OfficeFileAPI/401197/word-processing-document-api/examples/text/how-to-insert-dynamic-content)
* [How to: Replace a Placeholder with a Document Element](https://docs.devexpress.com/OfficeFileAPI/404369/word-processing-document-api/examples/search-and-replace/how-to-replace-a-placeholder-with-a-document-element)
<!-- feedback -->
## Does this example address your development requirements/objectives?

[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=word-document-api-mail-merge&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=word-document-api-mail-merge&~~~was_helpful=no)

(you will be redirected to DevExpress.com to submit your response)
<!-- feedback end -->
Binary file added media/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.