Generate TSV/CSV with multi-line cells that open in Numbers

csvnumbers

I want to programmatically generate tsv files with multi-line cells that stay preserved when opened in Numbers app.

What newline character to use to enable multi-line cells?

Best Answer

CSV is kind of standardized with RFC 4180. For multi-line fields the rules are

  • MS-DOS-style lines that end with (CR/LF) characters (optional for the last line).
  • Any field may be quoted (with double quotes).
  • Fields containing a line-break, double-quote or commas should be quoted.
  • If double-quotes are used to enclose fields, then a double-quote must be represented by two double-quote characters.

If this doesn't work with Numbers, you can also create a Numbers file, add some multi-line fields, export the file as CSV/TSV and verify the encoding/quoting used with TextEdit afterwards.

From the comment of @user3439894:

When Numbers exports to CSV it uses CR/LF between rows but uses LF for multi-line cells and the value is in double-quotes.