Fix empty data reader issue. (#629)

Co-authored-by: Lukasz Arciszewski <lukasz.arciszewski@accenture.com>
This commit is contained in:
duszekmestre 2024-07-13 03:21:49 +02:00 committed by GitHub
parent c0c8621e94
commit 7ecf0ffe69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 1 deletions

View File

@ -143,7 +143,10 @@ namespace MiniExcelLibs.OpenXml
if (_printHeader)
{
PrintHeader(writer, props);
yIndex++;
if (props.Count > 0)
{
yIndex++;
}
}
while (reader.Read())

View File

@ -3,6 +3,7 @@ using MiniExcelLibs.Attributes;
using MiniExcelLibs.OpenXml;
using MiniExcelLibs.Tests.Utils;
using Newtonsoft.Json;
using NSubstitute;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
@ -705,6 +706,19 @@ namespace MiniExcelLibs.Tests
}
}
[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>

View File

@ -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" />