Excel Close (Session)
Excel Close (Session)
Section titled “Excel Close (Session)”Type: excel-close · Package: Excel Activities v1.0.6 · Output: —
Saves and closes an Excel session opened with Excel Open. It is Excel Open’s required partner in session mode: it writes the changes to disk and releases the workbook from memory.
How it works
Section titled “How it works”It saves the session’s pending changes to the path it was opened with (unless you set save = false) and closes it. Once closed, the session can no longer be used: a later Excel Save on it saves nothing.
- Closing the same session twice does not fail: the second time does nothing.
- Inside the
bodyof an Excel Open you can omitsession: it closes thebody’s workbook. - If you saved a copy with
savePathin Excel Save, Excel Close still saves to the original path.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanExcelSession | — | The session returned by Excel Open. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
save | bool | true | Save changes before closing. Set it to false to discard unsaved changes. |
Output
Section titled “Output”This activity does not return a value.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'session' must be a valid Excel session (use excel-open). | session is empty or is not an Excel session (for example, a path). Pass the output variable of Excel Open. |
The process cannot access the file '…' because it is being used by another process. | The file is open in Excel or another program when saving. Close it and retry. |
Workbooks need at least one worksheet. | The session started from a file that did not exist and no sheet was written. Write something first or close with save = false. |
Example
Section titled “Example”Excel Open path = asset("report.xlsx") → output: workbookWrite Excel Cell session = workbook cell = "A1" value = "Processed"Excel Close session = workbookDiscard the changes (for example, after a failed validation):
Excel Close session = workbook save = falseRelated activities
Section titled “Related activities”- Excel Open — open the session.
- Excel Save — save without closing (for intermediate saves).