Skip to content

Commit

Permalink
Added CancellationToken support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tchial0 committed Aug 2, 2023
1 parent 476c82c commit 0b5db6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/MyExcel/Implementations/ExcelReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace MyExcel
Expand Down Expand Up @@ -56,7 +57,7 @@ public string FileLocation
/// <param name="column">Index (no 0-based) of the column in the spreadsheet</param>
/// <param name="startingRow">The row from which to start (default is 1).</param>
/// <returns>The enumerator of strings representing the selection.</returns>
public async Task<IEnumerable<string>> GetColumnAsync(uint column, uint startingRow = 1)
public async Task<IEnumerable<string>> GetColumnAsync(uint column, uint startingRow = 1, CancellationToken cancellationToken = default)
{
ThrowExceptionIfFileLocationNotSet();

Expand All @@ -65,6 +66,7 @@ public async Task<IEnumerable<string>> GetColumnAsync(uint column, uint starting
List<string> values = new List<string>();
for (uint row = startingRow; this[row, column] != string.Empty; row++)
{
cancellationToken.ThrowIfCancellationRequested();
values.Add(((dynamic)_sheet.Cells[row, column]).Value.ToString());
}
return values;
Expand Down Expand Up @@ -95,7 +97,7 @@ public IEnumerable<string> GetColumn(uint column, uint startingRow = 1)
/// <param name="row">Index (no 0-based) of the row in the spreadsheet</param>
/// <param name="startingColumn">The column from which to start (default is 1).</param>
/// <returns>The enumerator of strings representing the selection.</returns>
public async Task<IEnumerable<string>> GetRowAsync(uint row, uint startingColumn = 1)
public async Task<IEnumerable<string>> GetRowAsync(uint row, uint startingColumn = 1, CancellationToken cancellationToken = default )
{
ThrowExceptionIfFileLocationNotSet();

Expand Down
5 changes: 3 additions & 2 deletions src/MyExcel/Interfaces/IExcelReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace MyExcel
Expand Down Expand Up @@ -30,15 +31,15 @@ public interface IExcelReader
/// <param name="column">Index (no 0-based) of the column in the spreadsheet</param>
/// <param name="startingRow">The row from which to start (default is 1).</param>
/// <returns>The enumerator of strings representing the selection.</returns>
Task<IEnumerable<string>> GetColumnAsync(uint column, uint startingRow = 1);
Task<IEnumerable<string>> GetColumnAsync(uint column, uint startingRow = 1, CancellationToken cancellationToken = default);

/// <summary>
/// Get an enumerator of strings asynchronously representing an horizontal selection from the spreadsheet.
/// </summary>
/// <param name="row">Index (no 0-based) of the row in the spreadsheet</param>
/// <param name="startingColumn">The column from which to start (default is 1).</param>
/// <returns>The enumerator of strings representing the selection.</returns>
Task<IEnumerable<string>> GetRowAsync(uint row, uint startingColumn = 1);
Task<IEnumerable<string>> GetRowAsync(uint row, uint startingColumn = 1, CancellationToken cancellationToken = default);

/// <summary>
/// Get an enumerator of strings representing a vertical selection from the spreadsheet.
Expand Down
9 changes: 5 additions & 4 deletions src/MyExcel/MyExcel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
<RepositoryUrl>https://github.com/Tchial0/myexcel</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>excel;write;read;excel-write;excel-read;</PackageTags>
<AssemblyVersion>1.2.1</AssemblyVersion>
<AssemblyVersion>1.2.2</AssemblyVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>1.2.1</Version>
<Version>1.2.2</Version>
<PackageReleaseNotes>This release includes:

- Bug fixes</PackageReleaseNotes>
- CancellationToken support</PackageReleaseNotes>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<PackageProjectUrl></PackageProjectUrl>
<FileVersion>1.2.1</FileVersion>
<FileVersion>1.2.2</FileVersion>
<IncludeSymbols>False</IncludeSymbols>
<UserSecretsId>800c78b2-5f91-4499-8632-cc649761db56</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 0b5db6d

Please sign in to comment.