diff --git a/samples/xlsx/TestEmptySelfClosingRow.xlsx b/samples/xlsx/TestEmptySelfClosingRow.xlsx new file mode 100644 index 0000000..a309ea8 Binary files /dev/null and b/samples/xlsx/TestEmptySelfClosingRow.xlsx differ diff --git a/src/MiniExcel/OpenXml/ExcelOpenXmlSheetReader.cs b/src/MiniExcel/OpenXml/ExcelOpenXmlSheetReader.cs index 100b415..1a56ae6 100644 --- a/src/MiniExcel/OpenXml/ExcelOpenXmlSheetReader.cs +++ b/src/MiniExcel/OpenXml/ExcelOpenXmlSheetReader.cs @@ -277,7 +277,11 @@ namespace MiniExcelLibs.OpenXml // row -> c if (!XmlReaderHelper.ReadFirstContent(reader)) + { + //Fill in case of self closed empty row tag eg. + yield return GetCell(useHeaderRow, maxColumnIndex, headRows, startColumnIndex); continue; + } // startcell pass rows if (rowIndex < startRowIndex) diff --git a/tests/MiniExcelTests/MiniExcelOpenXmlTests.cs b/tests/MiniExcelTests/MiniExcelOpenXmlTests.cs index 6afa983..1afc692 100644 --- a/tests/MiniExcelTests/MiniExcelOpenXmlTests.cs +++ b/tests/MiniExcelTests/MiniExcelOpenXmlTests.cs @@ -180,7 +180,7 @@ namespace MiniExcelLibs.Tests Assert.Equal(2d, rows[1]["B"]); Assert.Equal(null!, rows[2]["A"]); } - + [Fact()] public void CenterEmptyRowsQueryTest() { @@ -201,7 +201,7 @@ namespace MiniExcelLibs.Tests 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); @@ -252,6 +252,27 @@ namespace MiniExcelLibs.Tests } } + [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() {