I count rows in two worksheets like this:
foreach (WorksheetPart worksheetPart in workbookPart.WorksheetParts)
{
OpenXmlPartReader reader = new OpenXmlPartReader(worksheetPart);
if (count == 0)
{
while (reader.Read())
{
if (reader.ElementType == typeof(Row))
{
count_first++;
}
}
}
else if (count == 1)
{
while (reader.Read())
{
if (reader.ElementType == typeof(Row))
{
count_second++;
}
}
}
count++;
}
For both worksheets in count_first
and count_second
I get twice as much as there are rows with data. Why is that and what does it actually mean? Does it mean that OpenXML
parses each list twice?
EDIT
Well, I found a solution. To get it right away, I guess, you should keep this sacred knowledge in some secret place. So, here it is:
while (reader.Read())
{
if (reader.ElementType == typeof(Row))
{
do
{
count_first++;
} while (reader.ReadNextSibling());
}
}