Best way to loop though Range

Add-in Express™ Support Service
That's what is more important than anything else

Best way to loop though Range
 
Praveen Kumar




Posts: 23
Joined: 2008-02-02
I have a use case, where the users will select the columns they need from an Excel sheet. I need to prepare data by looping through all the used rows in the excel sheet and creating a dataset (list of objects) for only those columns selected.

My question is:
What is the best way to loop through all used rows and read cell data from columns by their name?

Thanks
Best Regards,
Praveen
Posted 27 Jul, 2022 01:47:14 Top
Andrei Smolin


Add-in Express team


Posts: 18338
Joined: 2006-05-11
Hello Praveen,

The best way to read and write multiple cell is to to construct an Excel.Range object pointing to these cells and get or set Range.Value (or Range.Value2). If the Range object points to a single cell, this property accepts and returns a single value. If the Range object represents multiple cells, this property returns an array.

If you select a complete column(s), the resulting array may be too large. To minimize it, construct your Range as an intersection of the selection and Used Range. If the resulting range is still too large, you can construct a series of Ranges each covering only part of the whole Range.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Jul, 2022 04:26:58 Top
Praveen Kumar




Posts: 23
Joined: 2008-02-02
Thank you for your quick reply.
Best Regards,
Praveen
Posted 27 Jul, 2022 08:14:06 Top