Back to Devexpress

Document.MailMergeAsync(DocumentFormat, CancellationToken) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-document-dot-mailmergeasync-x28-devexpress-dot-blazor-dot-richedit-dot-documentformat-system-dot-threading-dot-cancellationtoken-x29.md

latest3.9 KB
Original Source

Document.MailMergeAsync(DocumentFormat, CancellationToken) Method

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

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

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

Parameters

NameTypeDescription
formatDocumentFormat

The format of the resulting document.

|

Optional Parameters

NameTypeDefaultDescription
cancellationTokenCancellationTokennull

An object that propagates a cancellation notification.

|

Returns

TypeDescription
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 executes a mail merge operation and load the resulting document to the Rich Text Editor:

razor
<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);
        await richEdit.LoadDocumentAsync(result, DocumentFormat.OpenXml);
    }
    @* ... *@
}
csharp
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 BirthDate { get; set; }
        public Nullable 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

Mail Merge in Blazor Rich Text Editor

Document Class

Document Members

DevExpress.Blazor.RichEdit Namespace