Import a spreadsheet into a table

Bring a CSV or Excel file into Marfa as the rows of a table, see what would change before anything is saved, and import the file again without adding a row twice.

marfa rows import reads a spreadsheet file and writes each of its records as a row of a table, a list you keep in Marfa in columns. It reads CSV, TSV, JSON, JSON Lines and Excel .xlsx files. You need the marfa command signed in, as the Quickstart shows.

Look before you save

--preview shows what an import would do and saves nothing. Here cellar.csv has the columns Wine, Vintage, Bottles and Bought, and --new-table asks for a table made from them:

Terminal
marfa rows import --new-table "Wine cellar" cellar.csv --preview
3 rows read: 3 new, 0 changed, 0 already as the file says, 0 refused.
A new table titled "Wine cellar" will be made, with the columns wine (string), vintage (integer), bottles (integer), bought (string).
Bought looks like dates (DD/MM/YYYY): add --kind Bought=date --date-format Bought=DD/MM/YYYY to make it a date column.
Nothing was saved: --preview only shows what would change.

The preview also lists the first five new records as Marfa read them. Marfa never guesses a value. A date such as 03/04/2026 reads two ways, so a column of dates stays text until you name its layout, as the third line says.

Import into a new table

Run the command without --preview. It shows the same preview, asks, and saves only when you answer yes:

Terminal
marfa rows import --new-table "Wine cellar" cellar.csv \
  --kind Bought=date --date-format Bought=DD/MM/YYYY --match-key Wine
Save 3 new rows and 0 changed rows? [y/N] y
Made the table 01a2394d-d9f3-7687-8fca-fba3553ca5f4.
Saved 3 new rows and 0 changed rows; 0 rows were already as the file says.
To undo what was saved, undo each batch:
  marfa rows undo 01a2394d-d9f3-7687-8fca-fba3553ca5f4 table 01a2394d-da00-76cd-8bf1-ea828a240856

--match-key names the column that tells one record from another, here the wine's name. Two records that share a key are both refused, and the key finds each row when you import again. A script adds --yes to save without the question. Without a terminal, or with --json, nothing is saved unless --yes is there.

Import the file again

After you change the spreadsheet, import it into the same table. Name the table's ID, the table name table, and the same key:

Terminal
marfa rows import 01a2394d-d9f3-7687-8fca-fba3553ca5f4 table cellar.csv \
  --match-key Wine --date-format Bought=DD/MM/YYYY
4 rows read: 1 new, 1 changed, 2 already as the file says, 0 refused.
To be added (1), with the values the file gives:
  line 5 (key "Sancerre"): wine "Sancerre", vintage 2022, bottles 4, bought "2026-04-03"
Changes, with the value Marfa holds and the value in the file:
  line 2 (key "Chablis")
    bottles: in Marfa 3, from file 2

Only what differs is saved, so importing an unchanged file changes nothing.

  • Without a key, rows go only into an empty table, because a second import would add every record again.
  • A blank cell leaves the row's value as it is. Add --blanks clear to clear it instead.
  • A column of the file must match a column of the table, by name or label. Send one elsewhere with --map "Bought on=bought", or leave it out with --skip Notes.
  • A row that someone changed after the preview is left as it is, and the report names it.

When a record is refused

A record whose value doesn't fit its column is refused alone, and the others are saved. The preview names each one, with its line, its column and what to do, such as --time-zone Europe/London for a time written without a zone. Import and export file rules lists how each kind of value is read.

Undo an import

The report ends with the commands that undo it. marfa rows undo puts the rows back as they were before a batch. A large import is saved in several batches, and each has its own command. To remove a new table whole, move it to the bin with marfa items trash <id>.

To import records as items of a type, such as books or bookmarks, see Import a file as items. To get rows out again, see Export to a spreadsheet.

On this page