Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CsvHelper.Excel.Specs/Common/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 9 additions & 10 deletions src/CsvHelper.Excel.Specs/CsvHelper.Excel.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.95.4" />
<PackageReference Include="CsvHelper" Version="27.2.1" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.15.0" />
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.0.0" />
<PackageReference Include="System.Linq.Async" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="FluentAssertions" Version="6.9.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.4.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/CsvHelper.Excel.Specs/Parser/ExcelParserAsyncSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected async Task RunAsync()
{
var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)
{
ShouldSkipRecord = record => record.Record.All(string.IsNullOrEmpty)
ShouldSkipRecord = record => record.Row.Parser.Record.All(string.IsNullOrEmpty)
};
using var parser = new ExcelParser(Path, WorksheetName, csvConfiguration);
using var reader = new CsvReader(parser);
Expand Down Expand Up @@ -112,7 +112,7 @@ public async void RowsHaveData()
{
var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)
{
ShouldSkipRecord = record => record.Record.All(string.IsNullOrEmpty)
ShouldSkipRecord = record => record.Row.Parser.Record.All(string.IsNullOrEmpty)
};
using var parser = new ExcelParser(Path, WorksheetName, csvConfiguration );
using var reader = new CsvReader(parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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 => record.Row.Parser.Record.All(string.IsNullOrEmpty)
};
using var parser = new ExcelParser(Path, null, csvConfiguration);
Run(parser);
Expand Down
12 changes: 7 additions & 5 deletions src/CsvHelper.Excel/CsvHelper.Excel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<PropertyGroup>
<Description>An implementation of ICsvParser and ICsvSerializer from CsvHelper that reads and writes using the ClosedXml library.</Description>
<AssemblyTitle>CsvHelper for Excel</AssemblyTitle>
<VersionPrefix>27.2.1</VersionPrefix>
<VersionPrefix>30.0.1</VersionPrefix>
<Authors>Chris Young</Authors>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<DebugType>portable</DebugType>
<AssemblyName>CsvHelper.Excel</AssemblyName>
<OutputType>Library</OutputType>
Expand All @@ -13,10 +13,12 @@
<PackageProjectUrl>https://github.com/youngcm2/CsvHelper.Excel</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/youngcm2/CsvHelper.Excel/blob/master/LICENSE</PackageLicenseUrl>
<PackageOutputPath>./nupkg</PackageOutputPath>
<AssemblyVersion>30.1.7.5</AssemblyVersion>
<FileVersion>30.1.7.5</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.95.4" />
<PackageReference Include="CsvHelper" Version="27.2.1" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.15.0" />
<PackageReference Include="ClosedXML" Version="0.100.3" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/CsvHelper.Excel/ExcelParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public ExcelParser(Stream stream, CultureInfo culture, bool leaveOpen = false) :
/// <param name="culture">The culture.</param>
/// <param name="leaveOpen"><c>true</c> to leave the <see cref="TextWriter"/> open after the <see cref="ExcelParser"/> object is disposed, otherwise <c>false</c>.</param>
public ExcelParser(Stream stream, string sheetName, CultureInfo culture, bool leaveOpen = false) : this(stream,
sheetName, new CsvConfiguration(culture) {LeaveOpen= leaveOpen})
sheetName, new CsvConfiguration(culture))
{
_leaveOpen = leaveOpen;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor should just pass leaveOpen to the "master" constructor to be consistent

}

/// <summary>
Expand All @@ -106,7 +107,7 @@ public ExcelParser(string path, string sheetName, CsvConfiguration configuration
/// <param name="configuration">The configuration.</param>
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);

Expand All @@ -123,7 +124,6 @@ public ExcelParser(Stream stream, string sheetName, CsvConfiguration configurati
}

Context = new CsvContext(this);
_leaveOpen = Configuration.LeaveOpen;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this here, should result in this (and probably more) constructor(s) to have the option to set this directly instead.

}


Expand Down
9 changes: 4 additions & 5 deletions src/CsvHelper.Excel/ExcelWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public ExcelWriter(Stream stream, CultureInfo culture, bool leaveOpen = false) :
/// <param name="culture">The culture.</param>
/// <param name="leaveOpen"><c>true</c> to leave the <see cref="TextWriter"/> open after the <see cref="ExcelWriter"/> object is disposed, otherwise <c>false</c>.</param>
public ExcelWriter(Stream stream, string sheetName, CultureInfo culture, bool leaveOpen = false) : this(stream,
sheetName, new CsvConfiguration(culture) { LeaveOpen = leaveOpen })
sheetName, new CsvConfiguration(culture))
{

_leaveOpen = leaveOpen;
}

/// <summary>
Expand All @@ -101,11 +101,10 @@ private ExcelWriter(Stream stream, string sheetName, CsvConfiguration configurat
configuration)
{
configuration.Validate();
_worksheet = new XLWorkbook(XLEventTracking.Disabled).AddWorksheet(sheetName);
_worksheet = new XLWorkbook().AddWorksheet(sheetName);
this._stream = stream;

_leaveOpen = configuration.LeaveOpen;
_sanitizeForInjection = configuration.SanitizeForInjection;
_sanitizeForInjection = configuration.InjectionOptions == InjectionOptions.Escape;
}


Expand Down