diff --git a/src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs b/src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs index 79e211d6..0139c3c1 100644 --- a/src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs +++ b/src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs @@ -143,7 +143,10 @@ private void GenerateSheetByIDataReader(MiniExcelStreamWriter writer, IDataReade if (_printHeader) { PrintHeader(writer, props); - yIndex++; + if (props.Count > 0) + { + yIndex++; + } } while (reader.Read()) diff --git a/tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs b/tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs index a2e15d50..23efd893 100644 --- a/tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs +++ b/tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs @@ -3,6 +3,7 @@ using MiniExcelLibs.OpenXml; using MiniExcelLibs.Tests.Utils; using Newtonsoft.Json; +using NSubstitute; using OfficeOpenXml; using System; using System.Collections.Generic; @@ -705,6 +706,19 @@ public async Task Issue211() } } + [Fact] + public async Task EmptyDataReaderIssue() + { + var path = PathHelper.GetTempPath(); + + var reader = Substitute.For(); + MiniExcel.SaveAs(path, reader, overwriteFile: true); + + var q = await MiniExcel.QueryAsync(path, true); + var rows = q.ToList(); + Assert.Empty(rows); + } + /// /// [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) /// diff --git a/tests/MiniExcelTests/MiniExcelTests.csproj b/tests/MiniExcelTests/MiniExcelTests.csproj index 471d9992..c47a8dbf 100644 --- a/tests/MiniExcelTests/MiniExcelTests.csproj +++ b/tests/MiniExcelTests/MiniExcelTests.csproj @@ -24,6 +24,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +