ExcelDataReader - Get index of currently read row

2.4k Views Asked by At

I'm using ExcelDataReader to read .xlsx files.

using (var reader = ExcelReaderFactory.CreateReader(stream))
{
    for (bool canRead = true; canRead; canRead = reader.NextResult())
    {
        //reader.Read(); many times
    }
}

How to get the index of the row I'm currently reading? In other words, how many times reader.Read() has been called.

1

There are 1 best solutions below

0
On

You can try this

using (var stream = File.Open("Book1.xls", FileMode.Open, FileAccess.Read))
{
    using (var reader = ExcelReaderFactory.CreateReader(stream))
    {
        do
        {
            while (reader.Read())
            {
                Console.WriteLine($"Row: {reader.Depth} Values: {reader[0]}, {reader[1]}");
            }
        } while (reader.NextResult());
    }
}

Output
enter image description here