0

In the code below I read through a smartsheet from column to column running some code until it throws an outofrange exception whereby I make the cellNumber = 0, and increase the row number (in other words move to a new line).

while (rowNumber < totalRows)
{
   try
   {
        do code....
        cellNumber++
   } catch (System.ArgumentOutOfRangeException)
   {
   cellNumber = 0;
   rowNumber++;
   }
}

Is there anyway to only catch the out of range exception associated with cellNumber?

Danrex
  • 1,657
  • 4
  • 31
  • 44
  • 2
    Catching exceptions like `ArgumentException`, `NotSupportedException`, `NotImplementedException` is generally a bad idea in my mind, it would be better to avoid them from happening in the first place. – Matthew Mar 27 '15 at 05:03
  • I don't know anything about Smartsheet, but surely it provides some method you can call to determine the number of cells in the row in question? Then use that to control a nested loop, like @ragtimewilly is suggesting. – RenniePet Mar 27 '15 at 06:14
  • It does but I am using a Json file retrieved from smartsheets – Danrex Mar 29 '15 at 20:09
  • Matthew your absolutly right. It was my first time working with a json format and I should have just used a count. Thank you. – Danrex Mar 29 '15 at 20:37

1 Answers1

2

I would suggest doing something along these lines:

 foreach (Row row in sheet.Rows)
 {
     foreach (Cell c in row.Cells)
     {
         //  do code....
     }
 }
RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41