Skip to main content

Document.MailMergeAsync(DocumentFormat, MergeMode, Int32, CancellationToken) Method

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

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<byte[]> MailMergeAsync(
    DocumentFormat format,
    MergeMode mergeMode,
    int firstRecord,
    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.

firstRecord Int32

The index of the first exported record in the bound data source.

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 code sample below demonstrates how to merge data records starting with the second record, 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, 1);
        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