Skip to content

Commit

Permalink
Fix empty data reader issue. (#629)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Arciszewski <[email protected]>
  • Loading branch information
duszekmestre and Lukasz Arciszewski authored Jul 13, 2024
1 parent c0c8621 commit 7ecf0ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ private void GenerateSheetByIDataReader(MiniExcelStreamWriter writer, IDataReade
if (_printHeader)
{
PrintHeader(writer, props);
yIndex++;
if (props.Count > 0)
{
yIndex++;
}
}

while (reader.Read())
Expand Down
14 changes: 14 additions & 0 deletions tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MiniExcelLibs.OpenXml;
using MiniExcelLibs.Tests.Utils;
using Newtonsoft.Json;
using NSubstitute;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -705,6 +706,19 @@ public async Task Issue211()
}
}

[Fact]
public async Task EmptyDataReaderIssue()
{
var path = PathHelper.GetTempPath();

var reader = Substitute.For<IDataReader>();
MiniExcel.SaveAs(path, reader, overwriteFile: true);

var q = await MiniExcel.QueryAsync(path, true);
var rows = q.ToList();
Assert.Empty(rows);
}

/// <summary>
/// [When reading Excel, can return IDataReader and DataTable to facilitate the import of database. Like ExcelDataReader provide reader.AsDataSet() · Issue #216 · shps951023/MiniExcel](https://github.com/shps951023/MiniExcel/issues/216)
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions tests/MiniExcelTests/MiniExcelTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NPOI" Version="2.7.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />

Expand Down

0 comments on commit 7ecf0ff

Please sign in to comment.