ref = xlsx.CellRange(id, startx, starty, endx, endy[, sheet]) ref = xlsx.CellRange(id, startcell$, endcell$[, sheet])
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.
startx
and starty
are omittedendx
and endy
are omittedxlsx.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.