Skip to content

Commit

Permalink
Use true async processing for excel writer (#573)
Browse files Browse the repository at this point in the history
* Use true async processing for excel writer

* Add async processing to other methods

---------

Co-authored-by: Lukasz Arciszewski <lukasz.arciszewski@accenture.com>
  • Loading branch information
duszekmestre and Lukasz Arciszewski authored Mar 24, 2024
1 parent 4a66779 commit 7894e28
Show file tree
Hide file tree
Showing 5 changed files with 730 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/MiniExcel/MiniExcel.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public static partial class MiniExcel
{
public static async Task SaveAsAsync(string path, object value, bool printHeader = true, string sheetName = "Sheet1", ExcelType excelType = ExcelType.UNKNOWN, IConfiguration configuration = null, bool overwriteFile = false,CancellationToken cancellationToken = default(CancellationToken))
{
await Task.Run(() => SaveAs(path, value, printHeader, sheetName, excelType, configuration, overwriteFile),cancellationToken).ConfigureAwait(false);
if (Path.GetExtension(path).ToLowerInvariant() == ".xlsm")
throw new NotSupportedException("MiniExcel SaveAs not support xlsm");

using (var stream = overwriteFile ? File.Create(path) : new FileStream(path, FileMode.CreateNew))
await SaveAsAsync(stream, value, printHeader, sheetName, ExcelTypeHelper.GetExcelType(path, excelType), configuration);
}

public static async Task SaveAsAsync(this Stream stream, object value, bool printHeader = true, string sheetName = "Sheet1", ExcelType excelType = ExcelType.XLSX, IConfiguration configuration = null,CancellationToken cancellationToken = default(CancellationToken))
Expand Down
2 changes: 2 additions & 0 deletions src/MiniExcel/MiniExcel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Utils;
using Zip;

Expand Down
Loading

0 comments on commit 7894e28

Please sign in to comment.