Workbook
objectAn Excel workbook that is open in memory: get its sheets, change them and save the workbook. Nothing is written to disk before `save`.
- Kind Object
- Library Xlsx
- Category Files & Documents
- Functions 3
How to get one
local workbook = Xlsx.open(location)Returned by
Leads to
Functions
sheet()
Section titled “sheet()”workbook.sheet(sheetName: string)→Sheet Returns the sheet with the given name. Throws `Xlsx.sheet could not find sheet` when the workbook has no such sheet.
Parameters
-
sheetNamestring - Name of the sheet, as on its tab
Returns
Example runs in CI
local workbook = Xlsx.open("template.xlsx")local sheet = workbook.sheet("Sheet1")print(sheet.getCell(1, 1))workbook.close()save()
Section titled “save()”workbook.save(fileLocation: string)→selfworkbook.save(fileLocation: string, saveMode: string)→self Writes the workbook to a file, replacing it if it exists. `.xlsx` is added when the name does not end with it. The folder must already exist (create it with `Fl.mkdir`); the call does not create folders. By default all formulas are recalculated before writing, so cells that other cells depend on have current values when the file is opened. With the mode `no-evaluate` the formulas are not recalculated: their cached results may be stale, but unrelated invalid formulas cannot make the save fail. That mode keeps all formulas as they are, so it is not a way to clean an untrusted spreadsheet. Throws `Xlsx.save failed` when the file cannot be written (for example because it is open in Excel) and for an unknown mode. Saving does not close the workbook.
Parameters
-
fileLocationstring - File to write, relative to the workspace
-
saveModestring optional - `evaluate` (default) recalculates formulas before writing, `no-evaluate` writes without recalculating. Case is ignored.
Returns
close()
Section titled “close()”workbook.close()→self Closes this workbook and frees its memory. Save first: unsaved changes are lost, and the workbook cannot be used afterwards.
Returns