Write Excel Sheet
Write Excel Sheet
Section titled “Write Excel Sheet”Type: excel-write-sheet · Package: Excel Activities v1.0.6 · Output: —
Writes an entire DataTable to an Excel sheet, including the column names as the first row. It is the most direct way to generate a report or export data to Excel. It creates the file and the sheet if they don’t exist.
How it works
Section titled “How it works”It takes the DataTable in data and writes it to the given sheet, starting at startCell. By default it clears the sheet first (clearSheet = true) and writes the headers (writeHeader = true). Accepts session or path — see the two modes.
- File and sheet: in fast mode, if the file does not exist it is created (with any missing folders); if the sheet does not exist, it is created. Without
sheet, it writes to the first sheet (or createsSheet1in a new workbook). clearSheet = trueclears the whole sheet — values and formatting — before writing, not just the area you are about to fill.- Values: numbers, dates and booleans are stored with their type; text is stored as text (even if it looks like a number).
DBNullor null cells are not written. See how the data arrives. - In fast mode it saves the file when done; in session mode the change stays in memory until Excel Save or Excel Close.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
data | DataTable | — | The DataTable to write. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanExcelSession | — | Excel Open session (instead of path). |
path | string | — | Path to the .xlsx (created if it doesn’t exist; required if there is no session). |
sheet | string | int | — | Sheet name or index; created if it doesn’t exist. If omitted, the first sheet (or "Sheet1" in a new workbook). |
writeHeader | bool | true | Write the column names as the first row. |
startCell | string | "A1" | Top-left cell to start writing at. |
clearSheet | bool | true | Clear the whole sheet (values and formatting) before writing. |
Output
Section titled “Output”This activity does not return a value.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'data' is required. | data is empty or the expression returned null. |
'data' must be a DataTable. | data is not a DataTable (for example, a list). Build one with Build DataTable. |
'session' or 'path' is required. | Neither session nor path is set. |
'…' is not A1 address or workbook named range. | startCell is not a valid address. Use the form "B2". |
sheetName '…' is invalid - character count MUST be greater than or equal to 1 and less than or equal to 31 | The new sheet’s name is longer than 31 characters. |
Invalid char (…) found at index (…) in sheet name '…' | The sheet name contains a character that is not allowed (/ \ ? * [ ] :). |
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 or retry with Retry. |
Example
Section titled “Example”Read Excel Sheet path = asset("sales.xlsx") → output: sales... process ...Write Excel Sheet path = "C:/output/report.xlsx" sheet = "Summary" data = salesWrite a table below a title, without clearing the rest of the sheet:
Write Excel Sheet path = "C:/output/report.xlsx" sheet = "Summary" data = sales startCell = "A3" clearSheet = falseRelated activities
Section titled “Related activities”- Write Excel Range — write values at a position without header logic.
- Append Excel Rows — add rows at the end without clearing.
- Read Excel Sheet — read a DataTable back.