Error exporting Excel sheet - Telerik.Windows.Documents.Spreadsheet

1 Answer 57 Views
Spreadsheet
Andrew
Top achievements
Rank 1
Andrew asked on 29 Nov 2024, 02:04 PM

I just updated to ASP>NET AJAX 2024 Q4 and I get an error in the following code...

string fileName = "SampleFile.xlsx"; 
 
IWorkbookFormatProvider formatProvider = new XlsxFormatProvider(); 
 
using (Stream output = new FileStream(fileName, FileMode.Create)) 
{ 
    formatProvider.Export(workbook, output); 
} 

'formatProvider.Export(workbook, output);' is looking for an additional parameter now 'TimeSpan? timeout'.

I took a guess and entered null and it seems to work.

What are the options for this new parameter?

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 29 Nov 2024, 02:19 PM | edited on 29 Nov 2024, 02:20 PM

Hi Andrew,

The Export method of the IWorkbookFormatProvider now requires an additional TimeSpan? timeout parameter. This parameter specifies the timeout duration after which the export operation will be canceled if not completed. Here are the options for this new parameter:

  • null: Passing null means there is no timeout, and the operation will continue until it is completed or canceled by other means. This is useful if you want the export operation to run without any time constraints.

  • TimeSpan value: You can specify a TimeSpan value to set a specific timeout duration. For example, TimeSpan.FromSeconds(30) will set a 30-second timeout for the export operation. If the operation exceeds this time, it will be canceled.

When to Use a Specific Timeout

Setting a specific timeout can be beneficial in scenarios where:

  • The export operation is part of a larger workflow that needs to complete within a certain timeframe.
  • You want to prevent the application from hanging indefinitely due to unexpected issues during the export process.
  • You are working within an environment with limited resources and need to manage operations efficiently.

Here's an example of how you can use this parameter:

string fileName = "SampleFile.xlsx";
IWorkbookFormatProvider formatProvider = new XlsxFormatProvider();

using (Stream output = new FileStream(fileName, FileMode.Create))
{
    // Set a 30-second timeout
    TimeSpan? timeout = TimeSpan.FromSeconds(30);
    formatProvider.Export(workbook, output, timeout);
}

You can adjust the TimeSpan value based on your application's requirements and the expected duration of the export operation. If you are satisfied with the operation using null, you can continue using it as is.

 

    Regards,
    Rumen
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Andrew
    Top achievements
    Rank 1
    commented on 29 Nov 2024, 02:27 PM

    Thanks so much for the explanation! Works great now.
    Tags
    Spreadsheet
    Asked by
    Andrew
    Top achievements
    Rank 1
    Answers by
    Rumen
    Telerik team
    Share this question
    or