From d181c255a0f8df92d3d145fb5ecffa30a45011b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20H=2E=20Primke?= Date: Fri, 9 Dec 2022 11:31:10 +0100 Subject: [PATCH 1/2] Update packages to newest versions - Fix issues with CsvHelper 30.0.1 --- .../CsvHelper.Excel.Specs.csproj | 20 +++++++++---------- .../Parser/ExcelParserAsyncSpec.cs | 6 +++--- .../Parser/ParseUsingPathSpecWithBlankRow.cs | 4 ++-- src/CsvHelper.Excel/CsvHelper.Excel.csproj | 6 +++--- src/CsvHelper.Excel/ExcelParser.cs | 12 +++++------ src/CsvHelper.Excel/ExcelWriter.cs | 13 ++++++------ 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj b/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj index 1cf116d..c6117d1 100644 --- a/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj +++ b/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj @@ -4,16 +4,16 @@ latest - - - - - - - - - - + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs b/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs index 7e2066d..5a09251 100644 --- a/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs +++ b/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs @@ -83,7 +83,7 @@ protected async Task RunAsync() { var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { - ShouldSkipRecord = record => record.Record.All(string.IsNullOrEmpty) + ShouldSkipRecord = record => Enumerable.Range(0, record.Row.ColumnCount).All(index => string.IsNullOrEmpty(record.Row[index])) }; using var parser = new ExcelParser(Path, WorksheetName, csvConfiguration); using var reader = new CsvReader(parser); @@ -112,7 +112,7 @@ public async void RowsHaveData() { var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { - ShouldSkipRecord = record => record.Record.All(string.IsNullOrEmpty) + ShouldSkipRecord = record => Enumerable.Range(0, record.Row.ColumnCount).All(index => string.IsNullOrEmpty(record.Row[index])) }; using var parser = new ExcelParser(Path, WorksheetName, csvConfiguration ); using var reader = new CsvReader(parser); @@ -130,4 +130,4 @@ public void Dispose() Helpers.Delete(Path); } } -} \ No newline at end of file +} diff --git a/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs b/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs index 1a288e7..15455b7 100644 --- a/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs +++ b/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs @@ -10,10 +10,10 @@ public ParseUsingPathSpecWithBlankRow() : base("parse_by_path_with_blank_row", i { var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { - ShouldSkipRecord = record => record.Record.All(string.IsNullOrEmpty) + ShouldSkipRecord = record => Enumerable.Range(0, record.Row.ColumnCount).All(index => string.IsNullOrEmpty(record.Row[index])) }; using var parser = new ExcelParser(Path, null, csvConfiguration); Run(parser); } } -} \ No newline at end of file +} diff --git a/src/CsvHelper.Excel/CsvHelper.Excel.csproj b/src/CsvHelper.Excel/CsvHelper.Excel.csproj index e809ce9..9d9cedd 100644 --- a/src/CsvHelper.Excel/CsvHelper.Excel.csproj +++ b/src/CsvHelper.Excel/CsvHelper.Excel.csproj @@ -15,8 +15,8 @@ ./nupkg - - - + + + \ No newline at end of file diff --git a/src/CsvHelper.Excel/ExcelParser.cs b/src/CsvHelper.Excel/ExcelParser.cs index 4a95186..41a6cd1 100644 --- a/src/CsvHelper.Excel/ExcelParser.cs +++ b/src/CsvHelper.Excel/ExcelParser.cs @@ -83,9 +83,8 @@ public ExcelParser(Stream stream, CultureInfo culture, bool leaveOpen = false) : /// The culture. /// true to leave the open after the object is disposed, otherwise false. public ExcelParser(Stream stream, string sheetName, CultureInfo culture, bool leaveOpen = false) : this(stream, - sheetName, new CsvConfiguration(culture) {LeaveOpen= leaveOpen}) - { - } + sheetName, new CsvConfiguration(culture), leaveOpen) + {} /// /// Initializes a new instance of the class. @@ -104,7 +103,8 @@ public ExcelParser(string path, string sheetName, CsvConfiguration configuration /// The stream. /// The sheet name /// The configuration. - public ExcelParser(Stream stream, string sheetName, CsvConfiguration configuration) + /// true to leave the open after the object is disposed, otherwise false. + public ExcelParser(Stream stream, string sheetName, CsvConfiguration configuration, bool leaveOpen = false) { var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); @@ -123,7 +123,7 @@ public ExcelParser(Stream stream, string sheetName, CsvConfiguration configurati } Context = new CsvContext(this); - _leaveOpen = Configuration.LeaveOpen; + _leaveOpen = leaveOpen; } @@ -212,4 +212,4 @@ private string[] GetRecord() return values; } } -} \ No newline at end of file +} diff --git a/src/CsvHelper.Excel/ExcelWriter.cs b/src/CsvHelper.Excel/ExcelWriter.cs index a5b8c6a..ee67dd3 100644 --- a/src/CsvHelper.Excel/ExcelWriter.cs +++ b/src/CsvHelper.Excel/ExcelWriter.cs @@ -86,7 +86,7 @@ public ExcelWriter(Stream stream, CultureInfo culture, bool leaveOpen = false) : /// The culture. /// true to leave the open after the object is disposed, otherwise false. public ExcelWriter(Stream stream, string sheetName, CultureInfo culture, bool leaveOpen = false) : this(stream, - sheetName, new CsvConfiguration(culture) { LeaveOpen = leaveOpen }) + sheetName, new CsvConfiguration(culture)) { } @@ -97,15 +97,16 @@ public ExcelWriter(Stream stream, string sheetName, CultureInfo culture, bool le /// The stream. /// The sheet name /// The configuration. - private ExcelWriter(Stream stream, string sheetName, CsvConfiguration configuration) : base(TextWriter.Null, - configuration) + /// true to leave the open after the object is disposed, otherwise false. + private ExcelWriter(Stream stream, string sheetName, CsvConfiguration configuration, bool leaveOpen = false) : base(TextWriter.Null, + configuration, leaveOpen) { configuration.Validate(); _worksheet = new XLWorkbook(XLEventTracking.Disabled).AddWorksheet(sheetName); this._stream = stream; - _leaveOpen = configuration.LeaveOpen; - _sanitizeForInjection = configuration.SanitizeForInjection; + _leaveOpen = leaveOpen; + _sanitizeForInjection = configuration.InjectionOptions != InjectionOptions.None ; } @@ -222,4 +223,4 @@ protected override async ValueTask DisposeAsync(bool disposing) } #endif } -} \ No newline at end of file +} From 112beaef7251c16a2d5fb26f702c712d4a88297c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20H=2E=20Primke?= Date: Fri, 3 Feb 2023 11:09:28 +0100 Subject: [PATCH 2/2] Fix: Update package CsvHelper to 30.0.1 --- src/CsvHelper.Excel.Specs/Common/Helpers.cs | 4 ++-- .../CsvHelper.Excel.Specs.csproj | 11 +++++------ .../Parser/ExcelParserAsyncSpec.cs | 6 +++--- .../Parser/ParseUsingPathSpecWithBlankRow.cs | 4 ++-- src/CsvHelper.Excel/CsvHelper.Excel.csproj | 10 ++++++---- src/CsvHelper.Excel/ExcelParser.cs | 14 +++++++------- src/CsvHelper.Excel/ExcelWriter.cs | 14 ++++++-------- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/CsvHelper.Excel.Specs/Common/Helpers.cs b/src/CsvHelper.Excel.Specs/Common/Helpers.cs index 51ba1d4..caf9587 100644 --- a/src/CsvHelper.Excel.Specs/Common/Helpers.cs +++ b/src/CsvHelper.Excel.Specs/Common/Helpers.cs @@ -9,12 +9,12 @@ public static XLWorkbook GetOrCreateWorkbook(string path, string worksheetName) { if (!File.Exists(path)) { - var workbook = new XLWorkbook(XLEventTracking.Disabled); + var workbook = new XLWorkbook(); workbook.GetOrAddWorksheet(worksheetName); workbook.SaveAs(path); return workbook; } - return new XLWorkbook(path, XLEventTracking.Disabled); + return new XLWorkbook(path); } public static IXLWorksheet GetOrAddWorksheet(this XLWorkbook workbook, string sheetName) diff --git a/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj b/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj index c6117d1..cf1db95 100644 --- a/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj +++ b/src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj @@ -2,15 +2,14 @@ net6.0 latest + 1.0.1.0 + 1.0.1.0 - - - - + - - + + diff --git a/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs b/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs index 5a09251..f717062 100644 --- a/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs +++ b/src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs @@ -83,7 +83,7 @@ protected async Task RunAsync() { var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { - ShouldSkipRecord = record => Enumerable.Range(0, record.Row.ColumnCount).All(index => string.IsNullOrEmpty(record.Row[index])) + ShouldSkipRecord = record => record.Row.Parser.Record.All(string.IsNullOrEmpty) }; using var parser = new ExcelParser(Path, WorksheetName, csvConfiguration); using var reader = new CsvReader(parser); @@ -112,7 +112,7 @@ public async void RowsHaveData() { var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { - ShouldSkipRecord = record => Enumerable.Range(0, record.Row.ColumnCount).All(index => string.IsNullOrEmpty(record.Row[index])) + ShouldSkipRecord = record => record.Row.Parser.Record.All(string.IsNullOrEmpty) }; using var parser = new ExcelParser(Path, WorksheetName, csvConfiguration ); using var reader = new CsvReader(parser); @@ -130,4 +130,4 @@ public void Dispose() Helpers.Delete(Path); } } -} +} \ No newline at end of file diff --git a/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs b/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs index 15455b7..3fd96fa 100644 --- a/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs +++ b/src/CsvHelper.Excel.Specs/Parser/ParseUsingPathSpecWithBlankRow.cs @@ -10,10 +10,10 @@ public ParseUsingPathSpecWithBlankRow() : base("parse_by_path_with_blank_row", i { var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { - ShouldSkipRecord = record => Enumerable.Range(0, record.Row.ColumnCount).All(index => string.IsNullOrEmpty(record.Row[index])) + ShouldSkipRecord = record => record.Row.Parser.Record.All(string.IsNullOrEmpty) }; using var parser = new ExcelParser(Path, null, csvConfiguration); Run(parser); } } -} +} \ No newline at end of file diff --git a/src/CsvHelper.Excel/CsvHelper.Excel.csproj b/src/CsvHelper.Excel/CsvHelper.Excel.csproj index 9d9cedd..48b940b 100644 --- a/src/CsvHelper.Excel/CsvHelper.Excel.csproj +++ b/src/CsvHelper.Excel/CsvHelper.Excel.csproj @@ -2,9 +2,9 @@ An implementation of ICsvParser and ICsvSerializer from CsvHelper that reads and writes using the ClosedXml library. CsvHelper for Excel - 27.2.1 + 30.0.1 Chris Young - netstandard2.0;netstandard2.1 + netstandard2.1 portable CsvHelper.Excel Library @@ -13,10 +13,12 @@ https://github.com/youngcm2/CsvHelper.Excel https://github.com/youngcm2/CsvHelper.Excel/blob/master/LICENSE ./nupkg + 30.1.7.5 + 30.1.7.5 - + - + \ No newline at end of file diff --git a/src/CsvHelper.Excel/ExcelParser.cs b/src/CsvHelper.Excel/ExcelParser.cs index 41a6cd1..16e5b6b 100644 --- a/src/CsvHelper.Excel/ExcelParser.cs +++ b/src/CsvHelper.Excel/ExcelParser.cs @@ -83,8 +83,10 @@ public ExcelParser(Stream stream, CultureInfo culture, bool leaveOpen = false) : /// The culture. /// true to leave the open after the object is disposed, otherwise false. public ExcelParser(Stream stream, string sheetName, CultureInfo culture, bool leaveOpen = false) : this(stream, - sheetName, new CsvConfiguration(culture), leaveOpen) - {} + sheetName, new CsvConfiguration(culture)) + { + _leaveOpen = leaveOpen; + } /// /// Initializes a new instance of the class. @@ -103,10 +105,9 @@ public ExcelParser(string path, string sheetName, CsvConfiguration configuration /// The stream. /// The sheet name /// The configuration. - /// true to leave the open after the object is disposed, otherwise false. - public ExcelParser(Stream stream, string sheetName, CsvConfiguration configuration, bool leaveOpen = false) + public ExcelParser(Stream stream, string sheetName, CsvConfiguration configuration) { - var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); + var workbook = new XLWorkbook(stream); _worksheet = string.IsNullOrEmpty(sheetName) ? workbook.Worksheet(1) : workbook.Worksheet(sheetName); @@ -123,7 +124,6 @@ public ExcelParser(Stream stream, string sheetName, CsvConfiguration configurati } Context = new CsvContext(this); - _leaveOpen = leaveOpen; } @@ -212,4 +212,4 @@ private string[] GetRecord() return values; } } -} +} \ No newline at end of file diff --git a/src/CsvHelper.Excel/ExcelWriter.cs b/src/CsvHelper.Excel/ExcelWriter.cs index ee67dd3..8768de2 100644 --- a/src/CsvHelper.Excel/ExcelWriter.cs +++ b/src/CsvHelper.Excel/ExcelWriter.cs @@ -88,7 +88,7 @@ public ExcelWriter(Stream stream, CultureInfo culture, bool leaveOpen = false) : public ExcelWriter(Stream stream, string sheetName, CultureInfo culture, bool leaveOpen = false) : this(stream, sheetName, new CsvConfiguration(culture)) { - + _leaveOpen = leaveOpen; } /// @@ -97,16 +97,14 @@ public ExcelWriter(Stream stream, string sheetName, CultureInfo culture, bool le /// The stream. /// The sheet name /// The configuration. - /// true to leave the open after the object is disposed, otherwise false. - private ExcelWriter(Stream stream, string sheetName, CsvConfiguration configuration, bool leaveOpen = false) : base(TextWriter.Null, - configuration, leaveOpen) + private ExcelWriter(Stream stream, string sheetName, CsvConfiguration configuration) : base(TextWriter.Null, + configuration) { configuration.Validate(); - _worksheet = new XLWorkbook(XLEventTracking.Disabled).AddWorksheet(sheetName); + _worksheet = new XLWorkbook().AddWorksheet(sheetName); this._stream = stream; - _leaveOpen = leaveOpen; - _sanitizeForInjection = configuration.InjectionOptions != InjectionOptions.None ; + _sanitizeForInjection = configuration.InjectionOptions == InjectionOptions.Escape; } @@ -223,4 +221,4 @@ protected override async ValueTask DisposeAsync(bool disposing) } #endif } -} +} \ No newline at end of file