.NET Spreadsheet (WinForms, WPF, Office File API) – Progress Indication (v21.1)

Our WinForms Spreadsheet and WPF Spreadsheet UI controls v21.1 ship with a built-in progress bar. This progress bar appears for the following operations (if the operations take longer than 500 milliseconds):

  • File Load and Save operations
  • Export to PDF and HTML

Our new progress bar is part of the WinForms and WPF Spreadsheet control’s built-in status bar. Add the status bar to your spreadsheet app or rebuild an existing status bar (for the WinForms Spreadsheet control) to leverage the capabilities of this new progress bar.

If you are new to our Spreadsheet control or are considering it for an upcoming project, please refer to the following web pages for more information:

Create a Custom Progress Indicator

If our predefined progress bar does not address your requirements, you can use IProgressIndicationService to create a custom progress indicator. Create a class that implements this interface and pass a class instance to the Spreadsheet control’s ReplaceService method to replace the default progress indicator service with your own service.

We created two examples that demonstrate how to implement custom progress indicators for our Spreadsheet UI controls. You can download these examples from the following GitHub repositories:

Spreadsheet Document API – Report Progress for Asynchronous Workbook Operations

We’ve added an IProgress<T> parameter to the following asynchronous methods to implement progress notifications:

Use the Progress<T> class as the default implementation of the IProgress<T> interface. <T> is an integer that defines progress percentage (from 0% to 100%).

The following code asynchronously loads and exports a workbook to PDF. The console window displays the progress of each operation. If the load or export operation takes longer than 30 seconds, it is canceled.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using DevExpress.Spreadsheet;
// ...
 
static async Task Main(string[] args) {
    var cancellationSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
    var cancellationToken = cancellationSource.Token;
    try {
       using (Workbook workbook = new Workbook()) {
           Console.WriteLine("Loading a document...");
           await workbook.LoadDocumentAsync("Document.xlsx", DocumentFormat.Xlsx,
               cancellationToken,
               new Progress<int>((progress) => Console.WriteLine($"{progress}%")));
           Console.WriteLine("Exporting to PDF...");
           using (FileStream pdfStream = new FileStream("Result.pdf", FileMode.Create))
           {
               await workbook.ExportToPdfAsync(pdfStream,
                  cancellationToken,
                  new Progress<int>((progress) => Console.WriteLine($"{progress}%")));
           }
           Console.WriteLine("Done!");
       }
    }
    catch (OperationCanceledException) {
        Console.WriteLine("Cancelled by timeout.");
    }
    finally {
        cancellationSource.Dispose();
    }
}

Your Feedback Matters

Should you have any questions/feedback regarding our WinForms and WPF Spreadsheet’s progress indicator, please comment here or submit a support ticket via the DevExpress Support Center. We will be happy to follow-up.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.