Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yield empty self-closing row tags as empty row during query. #673

Merged
merged 1 commit into from
Sep 28, 2024
Merged
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
Binary file added samples/xlsx/TestEmptySelfClosingRow.xlsx
Binary file not shown.
4 changes: 4 additions & 0 deletions src/MiniExcel/OpenXml/ExcelOpenXmlSheetReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ public IEnumerable<IDictionary<string, object>> Query(bool useHeaderRow, string

// row -> c
if (!XmlReaderHelper.ReadFirstContent(reader))
{
//Fill in case of self closed empty row tag eg. <row r="1"/>
yield return GetCell(useHeaderRow, maxColumnIndex, headRows, startColumnIndex);
continue;
}

// startcell pass rows
if (rowIndex < startRowIndex)
Expand Down
25 changes: 23 additions & 2 deletions tests/MiniExcelTests/MiniExcelOpenXmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void QueryRangeToIDictionary()
Assert.Equal(2d, rows[1]["B"]);
Assert.Equal(null!, rows[2]["A"]);
}

[Fact()]
public void CenterEmptyRowsQueryTest()
{
Expand All @@ -201,7 +201,7 @@ public void CenterEmptyRowsQueryTest()

Assert.Equal(null, rows[2].A);
Assert.Equal(2, rows[2].B);
Assert.Equal(null, rows[2].C);
Assert.Equal(null, rows[2].C);
Assert.Equal(4, rows[2].D);

Assert.Equal(null, rows[3].A);
Expand Down Expand Up @@ -252,6 +252,27 @@ public void CenterEmptyRowsQueryTest()
}
}

[Fact]
public void TestEmptyRowsQuerySelfClosingTag()
{
var path = @"../../../../../samples/xlsx/TestEmptySelfClosingRow.xlsx";
using (var stream = File.OpenRead(path))
{
var rows = stream.Query().ToList();

Assert.Equal(null, rows[0].A);
Assert.Equal(1, rows[1].A);
Assert.Equal(null, rows[2].A);
Assert.Equal(2, rows[3].A);
Assert.Equal(null, rows[4].A);
Assert.Equal(null, rows[5].A);
Assert.Equal(null, rows[6].A);
Assert.Equal(null, rows[7].A);
Assert.Equal(null, rows[8].A);
Assert.Equal(1, rows[9].A);
}
}

[Fact()]
public void TestDynamicQueryBasic_WithoutHead()
{
Expand Down
Loading