Clear Excel Range
Clear Excel Range
Section titled “Clear Excel Range”Type: excel-clear-range · Package: Excel Activities v1.0.6 · Output: —
Clears the contents of a cell range or of the whole sheet. Use it to clean up old data before writing new data, or to empty a temporary work area. It can optionally clear the formatting too (colors, borders), not just the values.
How it works
Section titled “How it works”It empties the cells of the given range (or, if you leave it out, the whole used range of the sheet). By default it clears only the contents — values and formulas — and keeps the formatting; with clearFormat = true it clears everything, formatting included. Accepts session or path — see the two modes.
- Unlike the other write activities, the file and the sheet must exist.
- On an empty sheet, without
range, it does nothing and does not fail. - In fast mode it saves the file when done; in session mode, on Excel Save or Excel Close.
Required parameters
Section titled “Required parameters”None — but you must set session or path (or be inside the body of an Excel Open).
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanExcelSession | — | Excel Open session (instead of path). |
path | string | — | Path to the .xlsx (required if there is no session). The file must exist. |
sheet | string | int | — | Sheet name or 1-based index. If omitted, the first sheet. |
range | string | — | Range to clear, e.g. "A1:D20", or a single cell ("B3"). If omitted, the whole used range. |
clearFormat | bool | false | Also clear the cells’ formatting. With false, only the contents. |
Output
Section titled “Output”This activity does not return a value.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'session' or 'path' is required. | Neither session nor path is set. |
File not found. | path does not exist. This activity does not create files. |
There isn't a worksheet named '…'. | No sheet has that name. |
There isn't a worksheet associated with that position. | The sheet index does not exist (or the name is just a number and was taken as an index). |
'…' is not A1 address or named range. | range is not a valid address. |
The process cannot access the file '…' because it is being used by another process. | The file is open in another program when saving. Close it or retry with Retry. |
Example
Section titled “Example”Clear a results sheet before filling it again:
Excel Open path = asset("dashboard.xlsx") → output: workbookClear Excel Range session = workbook sheet = "Results"Write Excel Sheet session = workbook sheet = "Results" data = newDataExcel Close session = workbookEmpty only the data block of a template, keeping titles and formatting:
Clear Excel Range path = "C:/reports/template.xlsx" sheet = "Detail" range = "A5:H500"Related activities
Section titled “Related activities”- Write Excel Sheet — write and clear the sheet in one step.
- Get Excel Used Range — find out which area has data.