From 0b5db6dea417496da7bf88eeb3b09a30c2bc600c Mon Sep 17 00:00:00 2001 From: Chialo Armando Date: Wed, 2 Aug 2023 18:09:24 +0100 Subject: [PATCH] Added CancellationToken support --- src/MyExcel/Implementations/ExcelReader.cs | 6 ++++-- src/MyExcel/Interfaces/IExcelReader.cs | 5 +++-- src/MyExcel/MyExcel.csproj | 9 +++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/MyExcel/Implementations/ExcelReader.cs b/src/MyExcel/Implementations/ExcelReader.cs index 3c61da1..1bcfbb3 100644 --- a/src/MyExcel/Implementations/ExcelReader.cs +++ b/src/MyExcel/Implementations/ExcelReader.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Runtime.InteropServices; +using System.Threading; using System.Threading.Tasks; namespace MyExcel @@ -56,7 +57,7 @@ public string FileLocation /// Index (no 0-based) of the column in the spreadsheet /// The row from which to start (default is 1). /// The enumerator of strings representing the selection. - public async Task> GetColumnAsync(uint column, uint startingRow = 1) + public async Task> GetColumnAsync(uint column, uint startingRow = 1, CancellationToken cancellationToken = default) { ThrowExceptionIfFileLocationNotSet(); @@ -65,6 +66,7 @@ public async Task> GetColumnAsync(uint column, uint starting List values = new List(); for (uint row = startingRow; this[row, column] != string.Empty; row++) { + cancellationToken.ThrowIfCancellationRequested(); values.Add(((dynamic)_sheet.Cells[row, column]).Value.ToString()); } return values; @@ -95,7 +97,7 @@ public IEnumerable GetColumn(uint column, uint startingRow = 1) /// Index (no 0-based) of the row in the spreadsheet /// The column from which to start (default is 1). /// The enumerator of strings representing the selection. - public async Task> GetRowAsync(uint row, uint startingColumn = 1) + public async Task> GetRowAsync(uint row, uint startingColumn = 1, CancellationToken cancellationToken = default ) { ThrowExceptionIfFileLocationNotSet(); diff --git a/src/MyExcel/Interfaces/IExcelReader.cs b/src/MyExcel/Interfaces/IExcelReader.cs index 2b49955..770aafa 100644 --- a/src/MyExcel/Interfaces/IExcelReader.cs +++ b/src/MyExcel/Interfaces/IExcelReader.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace MyExcel @@ -30,7 +31,7 @@ public interface IExcelReader /// Index (no 0-based) of the column in the spreadsheet /// The row from which to start (default is 1). /// The enumerator of strings representing the selection. - Task> GetColumnAsync(uint column, uint startingRow = 1); + Task> GetColumnAsync(uint column, uint startingRow = 1, CancellationToken cancellationToken = default); /// /// Get an enumerator of strings asynchronously representing an horizontal selection from the spreadsheet. @@ -38,7 +39,7 @@ public interface IExcelReader /// Index (no 0-based) of the row in the spreadsheet /// The column from which to start (default is 1). /// The enumerator of strings representing the selection. - Task> GetRowAsync(uint row, uint startingColumn = 1); + Task> GetRowAsync(uint row, uint startingColumn = 1, CancellationToken cancellationToken = default); /// /// Get an enumerator of strings representing a vertical selection from the spreadsheet. diff --git a/src/MyExcel/MyExcel.csproj b/src/MyExcel/MyExcel.csproj index 81b5c45..6c9b96c 100644 --- a/src/MyExcel/MyExcel.csproj +++ b/src/MyExcel/MyExcel.csproj @@ -9,17 +9,18 @@ https://github.com/Tchial0/myexcel git excel;write;read;excel-write;excel-read; - 1.2.1 + 1.2.2 README.md True - 1.2.1 + 1.2.2 This release includes: - - Bug fixes + - CancellationToken support False - 1.2.1 + 1.2.2 False + 800c78b2-5f91-4499-8632-cc649761db56