Name
xlsx.CellRange -- iterate over cell range
Synopsis
ref = xlsx.CellRange(id, startx, starty, endx, endy[, sheet])
ref = xlsx.CellRange(id, startcell$, endcell$[, sheet])
Function
This function can be used to iterate over a range of cells. You need to pass the cell where the iteration should start and the cell where it should end. xlsx.CellRange() will then return an iterator function which can be used together with Hollywood's generic for loop. The iterator function will return a reference to a cell that can be passed to all functions that deal with cells like xlsx.SetCellValue() or xlsx.GetCellValue().

Passing a cell reference returned by xlsx.CellRange() to functions like xlsx.SetCellValue() or xlsx.GetCellValue() is much faster than addressing the cell using its column and row position or its alphanumerical identifier (e.g. "A1"). That's why it's recommended to use xlsx.CellRange() whenever you need to iterate over lots of cells, especially in huge XLSX documents with thousands of columns and rows.

xlsx.CellRange() supports two ways of specifying the start and cells: You can either specify the cells to use by passing their column (x) and row (y) positions in the startx/§starty and endx/§endy arguments. Those positions start from 1 for the first column and row. Alternatively, you can also specify the cells by passing their alphanumerical references in the startcell$ and endcell$ parameters, e.g. "A10" for the first cell in the 10th row. Optionally, you can also pass the index of the worksheet to use in the optional sheet parameter (starting from 1 for the first worksheet). If the sheet parameter is omitted, the worksheet set by xlsx.SetDefaultSheet() will be used.

Inputs
id
identifier of the XLSX document to use
startx
column index of the start cell
starty
row index of the start cell
endx
column index of the end cell
endy
row index of the end cell
startcell$
alphanumerical start cell reference (e.g. "A1"), only used when startx and starty are omitted
endcell$
alphanumerical end cell reference (e.g. "Z100"), only used when endx and endy are omitted
sheet
optional: index of the worksheet to use (defaults to the index of the default worksheet)
Results
ref
a cell reference
Example
xlsx.Open(1, "test.xlsx")
cols = xlsx.GetColumnCount(1)
rows = xlsx.GetRowCount(1)
For ref In xlsx.CellRange(1, 1, 1, cols, rows)
   DebugPrint((xlsx.GetCellValue(1, ref)))
Next
xlsx.Close(1)
The code above opens test.xlsx and prints the values of all cells.

Show TOC