Access GridRow in a Worksheet

Iterate over the rows

Best Practices: if we want to access all the rows in the worksheet one by one, we can use iterators to traverse the existed rows. this will save memory.

   
// Accessing a row using iterators
   GridCells cells = GridWeb1.ActiveSheet.Cells;
   foreach (GridRow row in cells.Rows)
  {
      Console.WriteLine(row.Index+" "+row.Height);
   }

compare the below code ,this will create all the row object no matter whether it is null,thus will cause memory issues,so please do not use this way

 GridCells cells = GridWeb1.ActiveSheet.Cells;
 for(int r=0;r<=cells.MaxRow;r++)
 {
     GridRow row=cells.Rows[r];
     Console.WriteLine(row.Index+" "+row.Height);
 }

however you can use CheckRow method,to check if the row is empty

 GridCells cells = GridWeb1.ActiveSheet.Cells;
 for(int r=0;r<=cells.MaxRow;r++)
 {
     GridRow row=cells.CheckRow(r);
     if(row==null){
       Console.WriteLine("the row is empty:"+r);
     }else{
       Console.WriteLine(row.Index+" "+row.Height);
     }
 }