Skip to content

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.

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. DBNull or 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.
ParameterTypeDefaultDescription
dataDataTable | 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.
startCellstring—Top-left cell to start at, e.g. "B2".
ParameterTypeDefaultDescription
sessionZoanExcelSession—Excel Open session (instead of path).
pathstring—Path to the .xlsx (created if it doesn’t exist; required if there is no session).
sheetstring | int—Sheet name or index; created if it doesn’t exist. If omitted, the first sheet (or "Sheet1" in a new workbook).

This activity does not return a value.

MessageCause 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.

Write a data DataTable starting at a specific cell of a template:

Excel Open path = asset("template.xlsx") → output: workbook
Write Excel Range session = workbook startCell = "B5" data = sales // a DataTable obtained earlier
Write Excel Cell session = workbook cell = "C2" value = "Report " + month
Excel Save session = workbook savePath = "C:/reports/" + month + ".xlsx"
Excel Close session = workbook save = false

save = false on close leaves the original template untouched: the data only ends up in the copy saved with savePath.