Write Excel Range
Write Excel Range
Section titled “Write Excel Range”Type: excel-write-range · Package: Excel Activities v1.0.6 · Output: —
Writes values to the sheet starting at a specific cell, without treating any row as a header. It takes a DataTable, a single row as a DataRow or a list of rows (since version 1.0.6) and writes its data values — not the column names. Use it when you want to place data at an exact position — for example, filling in an Excel template that already has its own formatting and titles.
It is almost identical to Append Excel Range; the only difference is where it writes: Write Range, at the cell you specify (startCell); Append Range, automatically below the existing data.
How it works
Section titled “How it works”It places the values of data on the sheet starting at startCell and extending down and to the right. It does not clear the sheet or write headers: it only overwrites the cells it fills and keeps their formatting (which is why it suits templates). Accepts session or path — see the two modes.
- If the file or the sheet don’t exist, they are created.
- Numbers, dates and booleans are stored with their type; text, as text.
DBNullor null values are not written: those cells keep what they had. See how the data arrives. - In fast mode it saves the file when done; in session mode, on Excel Save or Excel Close.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
data | DataTable | DataRow | List<List<object>> | List<object> | — | The DataTable to write, a DataRow for a single row, a list of rows (arr(arr("a", 1), arr("b", 2)), or a JSON array of arrays) or a single row as a list (arr("a", 1)). Values are written, not headers. Lists are accepted since version 1.0.6. |
startCell | string | — | Top-left cell to start at, e.g. "B2". |
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). |
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. |
'startCell' is required. | startCell is missing. |
'data' must be a DataTable, a DataRow, a list of rows (List<List<object>>) or a single row (List<object>). | data is something else (for example, a text or a dictionary). |
'data' mixes rows (lists) and single values: pass a list of rows or a single row. | The list has both rows and single values, like arr(arr("a", 1), "b"). Put each value inside a row. |
'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. |
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”Write a data DataTable starting at a specific cell of a template:
Excel Open path = asset("template.xlsx") → output: workbookWrite Excel Range session = workbook startCell = "B5" data = sales // a DataTable obtained earlierWrite Excel Cell session = workbook cell = "C2" value = "Report " + monthExcel Save session = workbook savePath = "C:/reports/" + month + ".xlsx"Excel Close session = workbook save = falsesave = false on close leaves the original template untouched: the data only ends up in the copy saved with savePath.
Related activities
Section titled “Related activities”- Write Excel Sheet — write a DataTable with headers.
- Write Excel Cell — write a single cell.
- Read Excel Range — read a range into a DataTable.