Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 2262

Created Unassigned: Enumerator skips cells [15443]

$
0
0
When iterating over all cells of a column, some cells are skipped (e.g. row 6..11).
I tried to reproduce the error in a test method but was not successful.

The sourcecode of the Enumerator is very complex and the Enumerator is instantiated in the ExcelRangeBase class. This means only one iterator for a range is possible at the same time.
If you pass the range to a method and do a nested foreach loop there, then you will get errors.
I could not find this situation in my code but still could fix the Situation by implementing a simple iterator class for my purpose (see below):

private class RowColEnumerator : IEnumerable, IEnumerator
{
bool m_rowEnumerator;
int m_offset;
int m_row;
int m_column;
ExcelWorksheet m_worksheet;

public RowColEnumerator(bool rowEnumerator, int row, int col, ExcelWorksheet worksheet)
{
m_rowEnumerator = rowEnumerator;
m_offset = -1;
m_row = row;
m_column = col;
m_worksheet = worksheet;
}

public IEnumerator GetEnumerator()
{
return this;
}

public object Current
{
get
{
if (m_rowEnumerator)
{
return m_worksheet.Cells[m_row + m_offset, m_column];
}
else
{
return m_worksheet.Cells[m_row, m_column + m_offset];
}
}
}

public bool MoveNext()
{
m_offset++;
return m_offset < 32000;
}

public void Reset()
{
m_offset = -1;
}
}


Viewing all articles
Browse latest Browse all 2262

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>