From ff487e40021beea03e6ddaabab1a9762b2f9d4cd Mon Sep 17 00:00:00 2001 From: MarkPflug Date: Thu, 7 Sep 2023 11:38:10 -0700 Subject: [PATCH] Add release notes. Bump version. Obsolete Async method (wasn't properly async anyway). --- docs/ReleaseNotes.md | 4 ++++ source/Sylvan.Data.Excel/ExcelDataReader.cs | 18 ++++-------------- .../Sylvan.Data.Excel/Sylvan.Data.Excel.csproj | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 77297cf..8daafe8 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -1,5 +1,9 @@ # Sylvan.Data.Excel Release Notes +_0.4.16_ +- Adds ExcelFileType class that exposes constants about supported Excel formats: extensions and content types. +- Add `Obsolete` to `TryOpenWorksheetAsync`, use `TryOpenWorksheet` instead. Information about future Async strategy will be forthcoming. + _0.4.15_ - Fix a bug that prevented .xlsx reader from working on .NET Framework versions. - Fix a bug where FieldRowCount would be incorrect on empty rows. diff --git a/source/Sylvan.Data.Excel/ExcelDataReader.cs b/source/Sylvan.Data.Excel/ExcelDataReader.cs index 1a1a301..9de0ac7 100644 --- a/source/Sylvan.Data.Excel/ExcelDataReader.cs +++ b/source/Sylvan.Data.Excel/ExcelDataReader.cs @@ -8,7 +8,6 @@ using System.Globalization; using System.IO; using System.Linq; -using System.Net; using System.Threading; using System.Threading.Tasks; @@ -175,24 +174,12 @@ public static ExcelDataReader Create(Stream stream, ExcelWorkbookType fileType, } } - static readonly Dictionary FileTypeMap = new(StringComparer.OrdinalIgnoreCase) - { - { ".xls", ExcelWorkbookType.Excel }, - { ".xlsx", ExcelWorkbookType.ExcelXml }, - { ".xlsm", ExcelWorkbookType.ExcelXml }, - { ".xlsb", ExcelWorkbookType.ExcelBinary }, - }; - /// /// Gets the type of an Excel workbook from the file name. /// public static ExcelWorkbookType GetWorkbookType(string filename) { - var ext = Path.GetExtension(filename); - return - FileTypeMap.TryGetValue(ext, out var type) - ? type - : 0; + return ExcelFileType.FindForFilename(filename)?.WorkbookType ?? ExcelWorkbookType.Unknown; } /// @@ -202,7 +189,9 @@ public static ExcelWorkbookType GetWorkbookType(string filename) /// True if the sheet was opened, otherwise false. public bool TryOpenWorksheet(string name) { +#pragma warning disable // disable obsolete warning for now. return TryOpenWorksheetAsync(name).GetAwaiter().GetResult(); +#pragma warning enable } /// @@ -211,6 +200,7 @@ public bool TryOpenWorksheet(string name) /// The name of the worksheet to open. /// A cancellation token for the async operation. /// True if the sheet was opened, otherwise false. + [Obsolete("TryOpenWorksheetAsync will be removed in a future version. Use TryOpenWorksheet instead.")] public Task TryOpenWorksheetAsync(string name, CancellationToken cancel = default) { var sheetIdx = -1; diff --git a/source/Sylvan.Data.Excel/Sylvan.Data.Excel.csproj b/source/Sylvan.Data.Excel/Sylvan.Data.Excel.csproj index d3bdeac..0ec0757 100644 --- a/source/Sylvan.Data.Excel/Sylvan.Data.Excel.csproj +++ b/source/Sylvan.Data.Excel/Sylvan.Data.Excel.csproj @@ -3,7 +3,7 @@ net6.0;netstandard2.1;netstandard2.0 latest - 0.4.15 + 0.4.16 A cross-platform .NET library for reading Excel data files. excel;xls;xlsx;xlsb;datareader enable