xlsx.SetCellFormula(id, x, y, f$[, sheet]) xlsx.SetCellFormula(id, ref, f$[, sheet])
f$
. After
calling this function, xlsx.HaveCellFormula() will return True
. 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.
Note that the formula must be specified without the equal sign, e.g. you have to use "A1+A2" instead of "=A1+A2". Also note that the XLSX plugin won't compute the result of the formula, i.e. you can't expect xlsx.GetCellValue() to get the computation result after setting a cell formula. To have formula values computed, you need to open the XLSX document in Excel or LibreOffice's Calc and save it.
x
and y
are omittedxlsx.SetCellFormula(1, "A3", "A1+A2")The code above sets cell A3 to the sum of cells A1+A2.