This is a migrated thread and some comments may be shown as answers.

Iterating through rows of a sheet

2 Answers 170 Views
SpreadProcessing
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 04 Aug 2017, 02:26 PM

I'm attempting to iterate through the rows of each sheet in an opened Excel sheet - I'm replacing code that used the GemBox library. Previously, I used code like the following:

foreach (ExcelRow row in sheet.Rows)
{
   if (row != null)
   {
       ... do stuff ....
   }
}

 

Is the following the best conversion to using the Telerik library? Or is there a better way to only iterate through rows with content?

 

for (int i = 0; i < sheet.Rows.Count; i++)
{
   var row = sheet.Cells[CellRange.FromRow(i)];
 
   if (row != null)
   {
       ... do stuff ....
   }
}

2 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 04 Aug 2017, 03:35 PM

I actually just found a post here that shows how to identify which cells are used or not, which is what I was looking for.

0
Tanya
Telerik team
answered on 07 Aug 2017, 03:08 PM
Hello Rob,

Indeed, the UsedCellRange property should help you implement the desired behavior. Please, note that the UsedCellRange property returns all the cells that have applied any property on them. With the GetUsedCellRange() method though you can obtain those cells that have a specific property set. You can read more and check how to use both members in the documentation article.

Hope this helps.

Regards,
Tanya
Progress Telerik

Tags
SpreadProcessing
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or