Export rows or items to a spreadsheet

Write one table's rows or one type's items to a CSV file that a spreadsheet opens, guard cells a spreadsheet would run as formulas, and import the file back after you edit it.

marfa rows export writes the rows of one table to a file, and marfa items export writes the items of one type. Both write CSV unless you ask for another format. To move everything an instance holds, make an archive instead. You need the marfa command signed in, as the Quickstart shows.

Export a table's rows

Name the table's item and the table. A table you keep by hand is named table:

Terminal
marfa rows export 01a2394d-d9f3-7687-8fca-fba3553ca5f4 table --output cellar.csv
Exported 4 rows of the table "table" to cellar.csv as csv.

The file's first column is each row's id, and the table's columns follow in the table's order.

Export a type's items

Name the type:

Terminal
marfa items export --type core.media.book --output books.csv
Exported 3 items of type core.media.book to books.csv as csv.

The columns are id, the type's fields, then tags. Archived items are included, and items in the bin are left out.

  • --filter exports only the items a filter selects, such as --filter 'properties.rating gte 5'.
  • --view <id> exports the items a saved view lists, in the view's order.

A file holds one type's fields, so a filter or a view that selects items of several types is refused, and the message names the types.

Choose a format

--format takes csv, tsv, json or jsonl, and the extension of --output chooses when you leave it out. An export can't write an Excel workbook: a spreadsheet opens the CSV. Without --output, the file goes to standard output.

The file at --output is replaced only once every record has been read, so an export that stops leaves the earlier file as it was.

Guard cells a spreadsheet would run

A spreadsheet may run a cell that starts with =, +, -, @, a tab or a carriage return as a formula. An export counts those cells:

1 text cell starts with =, +, -, @, a tab or a carriage return, which a spreadsheet may run as a formula when it opens the file. --guard-formulas puts an apostrophe before it.

Add --guard-formulas before you open a file that holds text you didn't write, such as saved web pages or messages. It works for CSV and TSV. The apostrophe becomes part of the text, so don't import a guarded file back.

Edit the file and import it back

An export is a file an import reads as it is. Change cells in the spreadsheet, save it as CSV, and import it with --match-id id, which finds each row or item by the id column:

marfa rows import 01a2394d-d9f3-7687-8fca-fba3553ca5f4 table cellar.csv --match-id id
marfa items import --type core.media.book --as reading-list --match-id id books.csv

Only the cells you changed are saved, and an unchanged file changes nothing. Import a spreadsheet into a table and Import a file as items show the preview and the undo.

On this page