Back to Devexpress

Document.MailMerge(MailMergeOptions, String, DocumentFormat) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-dot-mailmerge-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-mailmergeoptions-system-dot-string-devexpress-dot-xtrarichedit-dot-documentformat-x29.md

latest6.1 KB
Original Source

Document.MailMerge(MailMergeOptions, String, DocumentFormat) Method

SECURITY-RELATED CONSIDERATIONS

Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.

Merges data to the current document and saves the result to a file in the specified format. Allows you to set mail merge options.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
void MailMerge(
    MailMergeOptions options,
    string fileName,
    DocumentFormat format
)
vb
Sub MailMerge(
    options As MailMergeOptions,
    fileName As String,
    format As DocumentFormat
)

Parameters

NameTypeDescription
optionsMailMergeOptions

An object that contains options for the current merge.

| | fileName | String |

A name of the file to which the merged document is saved.

| | format | DocumentFormat |

An enumeration member that indicates the destination format.

|

Remarks

The MailMerge method merges the current document with records retrieved from the MailMergeOptions.DataSource property specified by the options parameter, and saves the merged document to a file.

The MailMerge method results in the Document.CalculateDocumentVariable event being fired for the Document object.

The following code snippets (auto-collected from DevExpress Examples) contain references to the MailMerge(MailMergeOptions, String, DocumentFormat) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-richedit-control-mail-merge/CS/MailMerge/Form1.cs#L56

csharp
// Export a mail-merged document in a new file
richEditControl1.Document.MailMerge(myMergeOptions, fileDialog.FileName, DocumentFormat.OpenXml);
System.Diagnostics.Process.Start(fileDialog.FileName);

winforms-richedit-use-images-in-mail-merge/CS/Form1.cs#L46

csharp
richEditControl1.Document.MailMerge(options, fileName, DocumentFormat.Rtf);

word-document-api-use-docvariable-fields/CS/Program.cs#L37

csharp
// Mail-merge the document
document.MailMerge(myMergeOptions, "Result.docx", DocumentFormat.OpenXml);
var p = new Process();

word-processing-use-images-in-richedit-mail-merge/CS/Program.cs#L41

csharp
richEditDocumentServer.Document.MailMerge(options, fileName, DocumentFormat.Rtf);

winforms-richedit-control-mail-merge/VB/MailMerge/Form1.vb#L51

vb
'Export the mail-merged document in a new file
richEditControl1.Document.MailMerge(myMergeOptions, fileDialog.FileName, DocumentFormat.OpenXml)
System.Diagnostics.Process.Start(fileDialog.FileName)

winforms-richedit-use-images-in-mail-merge/VB/Form1.vb#L38

vb
Dim fileName As String = System.IO.Directory.GetCurrentDirectory() & "MailMergeResult.rtf"
richEditControl1.Document.MailMerge(options, fileName, DocumentFormat.Rtf)
Dim processor As New Process()

word-document-api-use-docvariable-fields/VB/Program.vb#L31

vb
' Mail-merge the document
document.MailMerge(myMergeOptions, "Result.docx", DocumentFormat.OpenXml)
Dim processor As New Process()

word-processing-use-images-in-richedit-mail-merge/VB/Program.vb#L35

vb
richEditDocumentServer.Document.MailMerge(options, fileName, DocumentFormat.Rtf)

See Also

Document Interface

Document Members

DevExpress.XtraRichEdit.API.Native Namespace