Skip to Content
Vatson Office

CSV

The input of write_csv. Rows of cells, an optional header, the delimiter and decimals for the reader's locale.

write_csv takes rows of cells and writes a .csv that a spreadsheet opens correctly. Accents survive (a byte order mark is added when the text has non-ASCII characters), text that a spreadsheet would run as a formula is written as text, and amounts keep their decimals when you ask.

Open invoices CSV shown as a sheet
An open-invoices CSV, opened as a sheet

Choices for the reader

  • Delimiter. , by default. Use ; when the reader's locale writes decimals with a comma.
  • Decimals. A number loses trailing zeros (1200.50 becomes 1200.5). Set decimals per column, or "column" for each column's most decimals, or send the amount as a string.
  • Locale. With locale, numbers use that locale's decimal separator.
  • Header. Written as the first row exactly as given: when the person named the columns, copy their names character for character.

A full example

The input behind the open invoices list. The last customer name starts with =; the file writes it as text.

Fields

Generated from the schema the tools send to the model. A field with ? is optional.

FieldTypeDescription
filename?string (max 120 chars)File name without folders, e.g. 'Open invoices'. The .csv extension is added.
header?string[] (at most 500)Column names, written as the first row exactly as given. When the person named the columns, copy their names character for character: same case (lower case stays lower case), accents, spelling and order
rows((string | number | boolean | null)[])[] (at most 100,000)Data rows; each row is a list of cells. A number loses trailing zeros (1200.50 becomes 1200.5): send an amount whose decimals must stay as a string, or set decimals
delimiter?"," | ";" | "\t"Default ','. Use ';' when the reader's locale writes decimals with a comma
bom?booleanStart with a UTF-8 byte order mark so Excel reads accents correctly. Default: only when the text has non-ASCII characters
locale?string (min 2 chars, max 35 chars)BCP 47 tag; when set, numbers use that locale's decimal separator
decimals?"column" | (integer | null)[]Decimals of number cells: one count per column (null leaves a column as is), e.g. [null, 2] writes 1200.5 as 1200.50; or 'column' for each column's most decimals

On this page