DEV Community

IronSoftware
IronSoftware

Posted on • Originally published at ironsoftware.com

Select Excel Range

IronXL allows us to easily select and work with ranges in any Excel WorkSheet.

C#:

using System.Linq;
using IronXL;

WorkBook workbook = WorkBook.Load("test.xls");
WorkSheet sheet = workbook.WorkSheets.First();

//This is how we get range from Excel worksheet
var range = sheet["A2:A8"];

//This is how we can iterate over our range
foreach (var cell in range)
{
    Console.WriteLine(cell.Value);
}
Enter fullscreen mode Exit fullscreen mode

VB:

Imports System.Linq
Imports IronXL

Private workbook As WorkBook = WorkBook.Load("test.xls")
Private sheet As WorkSheet = workbook.WorkSheets.First()

'This is how we get range from Excel worksheet
Private range = sheet("A2:A8")

'This is how we can iterate over our range
For Each cell In range
    Console.WriteLine(cell.Value)
Next cell
Enter fullscreen mode Exit fullscreen mode

Top comments (0)