I am working on an application that parses rows from a sheet in a xlsx file using Open XML with SAX. However, I was testing my implementation with a spreadsheet that has empty rows here and there. I would like to skip all the empty rows that I may find while I am looping through the rows in a sheet.
For example, I have the following spreadsheet
I opened up the spreadsheet using the Open XML Productivity tool and I found out that rows with empty cells all over have only one cell in the markup. That cell has an attribute called "s" that the other cells with cell values do not seem to have.
I was wondering if there is a way in code to find out if a given row is empty. So far what I am doing to go through the rows in the sheet is the following:
do{
if (reader.ElementType == typeof(Row))
{
reader.ReadFirstChild();
Type generatedType = typeBuilder.CreateType();
object generatedObject = Activator.CreateInstance(generatedType);
PropertyInfo[] properties = generatedType.GetProperties();
int propertiesCounter = 0;
// Read all the cells in the row.
do
{
if (reader.ElementType == typeof(Cell))
{
c = (Cell)reader.LoadCurrentElement();
if (c.DataType != null
&& c.DataType.HasValue
&& c.DataType == CellValues.SharedString
&& int.Parse(c.CellValue.InnerText) < ssTable.ChildElements.Count)
{
value = ssTable.ChildElements[int.Parse(c.CellValue.InnerText)].InnerText ?? string.Empty;
}
else
{
if (c.CellValue != null && c.CellValue.InnerText != null)
{
value = c.CellValue.InnerText;
}
else
{
value = string.Empty;
}
}
Debug.WriteLine(value);
properties[propertiesCounter].SetValue(generatedObject, value, null);
propertiesCounter++;
}
} while (reader.ReadNextSibling());
listObjectsCustomClasses.Add(generatedObject);
}} while (reader.Read() && reader.ElementType == typeof(Row));
Thank you very much for your kind help!
EDIT: I just found this answer in SO that explains that "The s attribute refers to a style". However, I am still interested in a way to find out programatically if a row is totally void of information using Open XML.