How to iterate over a range of cells

May 2, 2012 at 8:05 PM


At first thanks for the great library.

Here is my problem:

I want to select a range of worksheet cells and iterate on them, but not in 'foreach cell' way.

I use code like:

var range = sheet.cells["C1:D10"];
for(int i=1; i<range.End.Row; i++)
   Console.WriteLine("{0} = {1}", range[i, 1].Address, range[i, 1].Value.toString());

But i'v got strange result:

A1 = "a1 value"


Actually i want loop through the rows of a range, not each cell.


May 15, 2012 at 7:14 PM

The range indexer uses absolute rows and cols for the entire sheet, so I guess you shoud set i to range.Start.Row instead of 1.