Work with Excel Ranges
A Range
represents a selection of one or more cells in Excel.
With IronXL we can Read, Add, Sum, Average, Min, Max and Set Values over any Range of Cells.
using IronXL; using System.Linq; 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 and read or edit any cell foreach (var cell in range) { Console.WriteLine(cell.Value); } // Another Example var oneMoreRange = sheet["A9:A10"]; //This is how we can combine our ranges into a single selection var resultRange = range + oneMoreRange; //Iterate over new range - get or set any Cell foreach (var cell in resultRange) { Console.WriteLine(cell.Value); }
Imports IronXL Imports System.Linq 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 and read or edit any cell For Each cell In range Console.WriteLine(cell.Value) Next cell ' Another Example Dim oneMoreRange = sheet("A9:A10") 'This is how we can combine our ranges into a single selection Dim resultRange = range + oneMoreRange 'Iterate over new range - get or set any Cell For Each cell In resultRange Console.WriteLine(cell.Value) Next cell
A Range
represents a selection of one or more cells in Excel.
With IronXL we can Read, Add, Sum, Average, Min, Max and Set Values over any Range of Cells.