Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

Workbook.LoadDocumentAsync(String, CancellationToken) Method

Loads a document asynchronously from a file.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Docs.v19.2.dll

Declaration

public Task<bool> LoadDocumentAsync(
    string fileName,
    CancellationToken cancellationToken
)

Parameters

Name Type Description
fileName String

A string that specifies a file to load (including the full path).

cancellationToken CancellationToken

A CancellationToken object used to trace the requests to cancel an operation.

Returns

Type Description
Task<Boolean>

A Task<TResult> object that return true if the document was loaded successfully; otherwise, false.

Remarks

The Spreadsheet uses the built-in IFormatDetectorService service implementation to detect the format of the loaded document.

If the format detection fails, the Workbook.InvalidFormatException event fires.

Handle the Workbook.DocumentLoaded event to determine when you can safely modify the loaded document.

The code example below shows how to asynchronously convert an XLSX file to PDF format:

private async void ConvertXlsx2PdfWithCancellation()
{
  using (CancellationTokenSource source = new CancellationTokenSource(10000))
  {
    using (Workbook workbook = new Workbook())
      {
          try
          {
              await workbook.LoadDocumentAsync("Document.xlsx", source.Token);
              await workbook.ExportToPdfAsync("Result.pdf", source.Token);
          }
          catch (OperationCanceledException)
          {
              // Your code to handle cancellation.
          }
      }
  }
}
See Also