Name
xlsx.SetCellValue -- set cell value
Synopsis
xlsx.SetCellValue(id, x, y, val[, type, sheet])
xlsx.SetCellValue(id, ref, val[, type, sheet])
Function
This function sets the value of the specified cell to the value specified in 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
An integer value.

#DOUBLE
A floating point value.

#STRING
A string value.

#BOOLEAN
A boolean value (either True or False).

#NIL
This is a special type that will clear the cell.

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.

Inputs
id
identifier of the XLSX document to use
x
column index of the cell to use (starting from 1)
y
row index of the cell to use (starting from 1)
ref
cell reference (e.g. "A1" or an iterator state), only used when x and y are omitted
val
desired cell value
type
optional: type of the value (see above for possible constants)
sheet
optional: index of the worksheet to use (defaults to the index of the default worksheet)
Example
xlsx.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.

Show TOC