xlsx.SetCellValue(id, x, y, val[, type, sheet]) xlsx.SetCellValue(id, ref, val[, type, sheet])
val
. There are
two ways of specifying the cell whose value should be set: You can either specify
the cell to use by passing the cell's column (x) and row (y) position in the x
and y
arguments. Those positions start from 1 for the first column and row. Alternatively, you
can also specify the cell by passing its reference in the ref
parameter. This can either
be a string, e.g. "A10" for the first cell in the 10th row, or an iterator state returned
by the xlsx.CellRange() function. 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.
Optionally, you can also specify the value type in the type
argument. Normally, this is not necessary
since xlsx.SetCellValue()
will determine the value type based on the type of the argument
you pass in val
but since Hollywood doesn't distinguish between boolean, integer, and
floating point values it might be necessary to pass the type
parameter in order to make
sure the cell is set to the desired type. The type
parameter can be one of the following
special constants:
#INTEGER
#DOUBLE
#STRING
#BOOLEAN
True
or False
).
#NIL
Note that when trying to get the values of many cells it's usually much faster to use the xlsx.CellRange() function together with a generic for loop to iterate over the desired cells. This is especially recommended when dealing with large XLSX documents that have thousands of cells.
x
and y
are omittedxlsx.Create(1, "test.xlsx") For Local y = 1 To 100 For Local x = 1 to 30 xlsx.SetCellValue(1, x, y, "Cell " .. x .. "/" .. y) Next Next xlsx.Save(1) xlsx.Close(1)The code above will create a new XLSX document and add 30 columns and 100 rows to it. The document will be saved as
test.xlsx
.