Skip to main content

Document.MailMergeAsync(DocumentFormat, MergeMode, CancellationToken) Method

Merges all records of the bound data source to the document template, separates merge ranges with the selected delimeter, and generates the resulting document.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v24.2.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<byte[]> MailMergeAsync(
    DocumentFormat format,
    MergeMode mergeMode,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
format DocumentFormat

The format of the resulting document.

mergeMode MergeMode

A delimiter that starts a new merged range.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
ValueTask<Byte[]>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is the resulting document.

Remarks

The following code snippet merges all data source records, separate merge ranges with paragraphs, and load the resulting document to the Rich Text Editor:

<DxRichEdit @ref=richEdit>
   <MailMergeSettings>
        <DxMailMergeSettings Data="@DataSource" ViewMergedData="true" ActiveRecord="1"/>
    </MailMergeSettings>
</DxRichEdit>

@code {
    IEnumerable<Employee> DataSource;
    protected override async Task OnInitializedAsync() {
        DataSource = await NwindDataService.GetEmployeesAsync();
        await base.OnInitializedAsync();
    }    
    async void ExecuteMailMerge() { 
        byte[] result = await richEdit.DocumentAPI.MailMergeAsync(DocumentFormat.OpenXml, MergeMode.NewParagraph);
        await richEdit.LoadDocumentAsync(result, DocumentFormat.OpenXml);
    }
    @* ... *@
}
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace BlazorDemo.Data.Northwind {
    public partial class Employee {
        public Employee() {
            this.Orders = new List<Order>();
        }
        public int EmployeeId { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public string Title { get; set; }
        public string TitleOfCourtesy { get; set; }
        public Nullable<System.DateTime> BirthDate { get; set; }
        public Nullable<System.DateTime> HireDate { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string HomePhone { get; set; }
        public string Extension { get; set; }
        public string Notes { get; set; }
        public Nullable<int> ReportsTo { get; set; }
        public string PhotoPath { get; set; }
        public virtual ICollection<Order> Orders { get; set; }
        public string Text => $"{FirstName} {LastName} ({Title})";
        public string ImageFileName => $"Employees/{EmployeeId}.jpg";
    }
}
See Also