diff --git a/.github/workflows/vale.yml b/.github/workflows/vale.yml new file mode 100644 index 0000000..068c35b --- /dev/null +++ b/.github/workflows/vale.yml @@ -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 diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..a88e69e --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @DevExpressExampleBot \ No newline at end of file diff --git a/CS/WordProcessingMailMerge/template.docx b/CS/WordProcessingMailMerge/template.docx index 4a0b21e..c179fb0 100644 Binary files a/CS/WordProcessingMailMerge/template.docx and b/CS/WordProcessingMailMerge/template.docx differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..bc6eb00 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ + +[![](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) + +# 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) + +## Does this example address your development requirements/objectives? + +[](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=word-document-api-mail-merge&~~~was_helpful=yes) [](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) + diff --git a/VB/WordProcessingMailMerge/template.docx b/VB/WordProcessingMailMerge/template.docx index 7db2d13..c179fb0 100644 Binary files a/VB/WordProcessingMailMerge/template.docx and b/VB/WordProcessingMailMerge/template.docx differ diff --git a/media/image.png b/media/image.png new file mode 100644 index 0000000..1fd8079 Binary files /dev/null and b/media/image.png differ