Skip to content

An Excel workbook that is open in memory: get its sheets, change them and save the workbook. Nothing is written to disk before `save`.

How to get one

  1. Xlsx .open()
  2. Workbook
local workbook = Xlsx.open(location)

Returned by

Leads to

Functions

  • sheet Sheet Returns the sheet with the given name.
  • save self Writes the workbook to a file, replacing it if it exists.
  • close self Closes this workbook and frees its memory.
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

sheetName string
Name of the sheet, as on its tab

Returns

Sheet One sheet of a workbook: read single cells, read whole columns grouped by header, and write cells.

Example runs in CI

local workbook = Xlsx.open("template.xlsx")
local sheet = workbook.sheet("Sheet1")
print(sheet.getCell(1, 1))
workbook.close()
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

fileLocation string
File to write, relative to the workspace
saveMode string optional
`evaluate` (default) recalculates formulas before writing, `no-evaluate` writes without recalculating. Case is ignored.

Returns

self chainable The workbook itself, so calls can be chained.
workbook.close()→self

Closes this workbook and frees its memory. Save first: unsaved changes are lost, and the workbook cannot be used afterwards.

Returns

self chainable The workbook itself, so calls can be chained.