All docs
V20.1
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

XtraReport.ExportToDocxAsync(String, DocxExportOptions, CancellationToken) Method

Asynchronously exports a report to the specified file in DOCX format.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.1.dll

Declaration

public Task ExportToDocxAsync(
    string path,
    DocxExportOptions options = null,
    CancellationToken token = default(CancellationToken)
)
Public Function ExportToDocxAsync(
    path As String,
    options As DocxExportOptions = Nothing,
    token As CancellationToken = Nothing
) As Task

Parameters

Name Type Description
path String

The path to the exported DOCX file.

Optional Parameters

Name Type Default Description
options DocxExportOptions

null

The DOCX export options. You can omit this parameter to use the current report export options.

token CancellationToken

null

A cancellation token that the task observes.

Returns

Type Description
Task

A task that exports the report.

Remarks

This method is equivalent to the ExportToDocx(String, DocxExportOptions) method but does not lock other actions performed concurrently. For instance, the user interface remains operational while the application exports a report.

Call ExportToDocxAsync from an async method. Prefix the call with the await operator, as shown in the code sample below.

The optional CancellationToken parameter provides a way to send the cancellation signal to the task. The task monitors the token and stops when it receives the signal. Create a CancellationTokenSource class instance and pass its Token property to the ExportToDocxAsync method call. Call the CancellationTokenSource.Cancel method to stop the task.

Example

The code sample below exports a report to DOCX asynchronously. A CancellationTokenSource class instance is used to allow users to interrupt the report export if it takes too long.

using System;
using System.Windows.Forms;
using System.Threading;
using DevExpress.XtraReports.UI;
// ...
// Use the cancellationTokenSource to allow users to stop the report export.
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
// ...
// The cancelButton_Click event handler uses cancellationTokenSource to stop the report export.
private void cancelButton_Click(object sender, EventArgs e) {
    cancellationTokenSource.Cancel();
}
// ...
public async void ExportReportToDocxFileAsync() {
    // Create a simple report.
    XtraReport report = new XtraReport() {
        Name = "SimpleReport",
        Bands = {
            new DetailBand() {
                Controls = {
                    new XRLabel() {
                        Text = "Simple Report"
                    }
                }
            }
        }
    };
    // Export the report. The export file is placed to the user's Downloads folder.
    await report.ExportToDocxAsync(
        Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + report.Name + ".docx",
        null,
        cancellationTokenSource.Token);
}
See Also