Skip to content

Commit

Permalink
Fix for #143: data skipped when headers disabled and blank lines at s…
Browse files Browse the repository at this point in the history
…tart of file.
  • Loading branch information
MarkPflug committed Nov 16, 2023
1 parent 7c46b33 commit e234cd4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Coverlet.Collector" Version="1.3.0"/>
<PackageReference Include="Coverlet.MSBuild" Version="2.9.0"/>
<PackageReference Include="ReportGenerator" Version="4.5.0"/>
Expand Down
4 changes: 4 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Sylvan.Data.Excel Release Notes

_0.4.18_
- Fix a bug where column filters were applied to one too many columns when writing .xlsb files.
- Fix a bug where data would be skipped when headers were disabled and a worksheet started with blank line(s).

_0.4.17_
- Exclude phonetic component when reading string values.
- Allow invalid ref values, which Excel appears to treat as missing.
Expand Down
33 changes: 31 additions & 2 deletions source/Sylvan.Data.Excel.Tests/ExcelDataReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void ErrorAsNull()
using var edr = ExcelDataReader.Create(file, opts);
Assert.True(edr.Read());
Assert.True(edr.IsDBNull(2));
Assert.True(edr.IsDBNullAsync(2).Result);
//Assert.True(edr.IsDBNullAsync(2));
Assert.Equal("", edr.GetString(2));
}

Expand Down Expand Up @@ -394,7 +394,7 @@ public void ErrorAsEmptyString()
using var edr = ExcelDataReader.Create(file, opts);
Assert.True(edr.Read());
Assert.False(edr.IsDBNull(2));
Assert.False(edr.IsDBNullAsync(2).Result);
//Assert.False(edr.IsDBNullAsync(2).Result);
Assert.Equal("", edr.GetString(2));
}

Expand Down Expand Up @@ -1061,6 +1061,35 @@ public void BlankFirstRow()
Assert.False(edr.Read());
}

[Fact]
public void BlankFirstRowNoHeader()
{
var file = GetFile("BlankFirstRow");
var o = new ExcelDataReaderOptions { Schema = ExcelSchema.NoHeaders };
using var edr = ExcelDataReader.Create(file, o);

Assert.Equal(0, edr.FieldCount);
Assert.Equal(0, edr.RowFieldCount);
Assert.True(edr.Read());
Assert.Equal(0, edr.FieldCount);
Assert.Equal(0, edr.RowFieldCount);
Assert.True(edr.Read());
Assert.Equal(0, edr.FieldCount);
Assert.Equal(4, edr.RowFieldCount);
Assert.Equal("", edr.GetString(0));
Assert.Equal("a", edr.GetString(1));
Assert.Equal("b", edr.GetString(2));
Assert.Equal("c", edr.GetString(3));
Assert.True(edr.Read());
Assert.Equal(0, edr.FieldCount);
Assert.Equal(4, edr.RowFieldCount);
Assert.Equal("", edr.GetString(0));
Assert.Equal("1", edr.GetString(1));
Assert.Equal("2", edr.GetString(2));
Assert.Equal("3", edr.GetString(3));
Assert.False(edr.Read());
}

[Theory]
[InlineData("Big")]
[InlineData("BlankFirstRow")]
Expand Down
2 changes: 1 addition & 1 deletion source/Sylvan.Data.Excel/Sylvan.Data.Excel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<VersionPrefix>0.4.17</VersionPrefix>
<VersionPrefix>0.4.18</VersionPrefix>
<Description>A cross-platform .NET library for reading Excel data files.</Description>
<PackageTags>excel;xls;xlsx;xlsb;datareader</PackageTags>
<Nullable>enable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion source/Sylvan.Data.Excel/Xlsb/XlsbWorkbookReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public override bool Read()
if (hasRows)
{
this.state = State.Open;
if (curFieldCount >= 0)
if (rowIndex == parsedRowIndex && curFieldCount >= 0)
{
this.rowFieldCount = curFieldCount;
this.curFieldCount = -1;
Expand Down
2 changes: 1 addition & 1 deletion source/Sylvan.Data.Excel/Xlsx/XlsxWorkbookReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public override bool Read()
if (hasRows)
{
this.state = State.Open;
if (curFieldCount >= 0)
if (rowIndex == parsedRowIndex && curFieldCount >= 0)
{
this.rowFieldCount = curFieldCount;
this.curFieldCount = -1;
Expand Down

0 comments on commit e234cd4

Please sign in to comment.