Skip to content

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.

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 creates Sheet1 in a new workbook).
  • clearSheet = true clears 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). DBNull or 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.
ParameterTypeDefaultDescription
dataDataTable—The DataTable to write.
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).
writeHeaderbooltrueWrite the column names as the first row.
startCellstring"A1"Top-left cell to start writing at.
clearSheetbooltrueClear the whole sheet (values and formatting) before writing.

This activity does not return a value.

MessageCause 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 31The 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.
Read Excel Sheet path = asset("sales.xlsx") → output: sales
... process ...
Write Excel Sheet path = "C:/output/report.xlsx" sheet = "Summary" data = sales

Write 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 = false