Skip to content

Commit

Permalink
Merge pull request #241 from toddlucas/master
Browse files Browse the repository at this point in the history
Fix XSSFExcelExtractor to emit empty cells
  • Loading branch information
tonyqus authored Jan 11, 2020
2 parents 1304e24 + 6b13de1 commit e918a6e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ooxml/XSSF/Extractor/XSSFExcelExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public override String Text
IRow row = (IRow)rawR;
IEnumerator ri =row.GetEnumerator();
bool firsttime=true;
while (ri.MoveNext())
for (int j = 0; j < row.LastCellNum; j++)
{
if (!firsttime)
{
Expand All @@ -202,7 +202,9 @@ public override String Text
{
firsttime = false;
}
ICell cell = (ICell)ri.Current;
ICell cell = (ICell)row.GetCell(j);
if (cell == null)
continue;

// Is it a formula one?
if (cell.CellType == CellType.Formula)
Expand Down
31 changes: 31 additions & 0 deletions testcases/ooxml/XSSF/Extractor/TestXSSFExcelExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,37 @@ public void TestInlineStrings()
Assert.IsTrue(text.Contains("A5-A$2"), "Unable to find expected word in text\n" + text);
extractor.Close();
}

[Test]
public void TestEmptyCells()
{
XSSFExcelExtractor extractor = GetExtractor("SimpleNormal.xlsx");

String text = extractor.Text;
Assert.IsTrue(text.Length > 0);

// This sheet demonstrates the preservation of empty cells, as
// signified by sequential \t characters.
Assert.AreEqual(
// Sheet 1
"Sheet1\n" +
"test\t\t1\n" +
"test 2\t\t2\n" +
"\t\t3\n" +
"\t\t4\n" +
"\t\t5\n" +
"\t\t6\n" +
// Sheet 2
"Sheet Number 2\n" +
"This is sheet 2\n" +
"Stuff\n" +
"1\t2\t3\t4\t5\t6\n" +
"1/1/90\n" +
"10\t\t3\n",
text);

extractor.Close();
}
}
}

Expand Down

0 comments on commit e918a6e

Please # to comment.