Export Tabular Data to CSV

What exporting a table to CSV keeps and what it drops, how quoting and delimiters work, and how to keep the file usable after sharing or importing.

Exporting a table to CSV (comma-separated values) turns rows and columns into plain text that almost any database, spreadsheet, or scripting tool can read. That portability is the main reason to do it. The tradeoff is that CSV stores values only, so anything that depended on the original file's structure or formatting is lost. This review explains what the conversion changes, where it tends to break, and when another format is a better choice.

Is CSV the right format for your data?

CSV is a good fit when the goal is to move flat, row-and-column data between systems, such as importing records into another application, feeding a script, archiving a simple dataset, or tracking changes line by line in version control. The format is simple enough to inspect in a text editor, which makes problems easier to find.

The deciding limitation is that CSV holds one flat table of text values and nothing else. If the data relies on several sheets, formulas, cell formatting, merged cells, charts, or explicit data types, an export will discard them. In that case, keep the native file as the working copy and treat the CSV as a derived export.

Other formats are sometimes a better fit:

  • Use a formatted table or plain prose when people will read a few values in a message or document. Raw CSV is awkward to read.
  • Use the native spreadsheet or database format when formulas, styling, or multiple tables must survive.
  • Use a structured format such as JSON when the data is nested or hierarchical rather than a single grid.

What the export actually changes

Exporting to CSV is a serialization step. Each row becomes a line of text, and each cell value is separated from the next by a delimiter, usually a comma. The characters inside the cells are not reversed, mirrored, or restyled. What changes is the container: visual presentation such as column widths, fonts, colors, and number display formats is replaced by bare stored values.

The widely cited description of the format is RFC 4180. It describes optional header rows, line breaks between records, and the quoting rules that let a field contain the delimiter itself. In practice, many programs deviate from it, so a file that follows those rules can still be read differently by different tools.

Quoting is the part most likely to go wrong. Under the common convention, a field that contains a comma, a double quote, or a line break is wrapped in double quotes. Any double quote inside such a field is written twice. The following three-line table shows each case:

id,name,note
1,"Smith, Jane","She said ""hello"""
2,Lee,"Line one
Line two"

In this example, the name field is quoted because it contains a comma. The first note has doubled quotes so that it reads back as She said "hello". The second note spans two physical lines but is still one field in one record. A parser that splits naively on commas or newlines would break all three, which is why a proper CSV library or import tool is safer than hand-written splitting.

CSV compared with TSV

Tab-separated values (TSV) follow the same idea with a tab character as the delimiter. Because commas are common in ordinary text and tabs are rare, TSV often needs less quoting. TSV conventions are less consistent than CSV conventions, though. Some tools expect quoting, and others forbid tabs or line breaks inside fields entirely.

Aspect | CSV | TSV
Delimiter | Comma (some locales use semicolons) | Tab character
Fields containing the delimiter | Must be quoted | Rare in typical text, but handling varies by tool
Readability in a text editor | Columns do not line up | Columns may line up loosely, depending on tab settings
Typical use | General data exchange and imports | Copying between spreadsheets, some data and scientific tools

Delimiters also vary by region. In regions where the comma is the decimal separator, some spreadsheet software exports with semicolons and expects semicolons on import. Check which delimiter the receiving system expects instead of assuming a comma.

Will the file stay usable after sharing or importing?

The file itself is plain text, so copying or sending it does not alter its contents. Problems usually appear when a program opens the file and interprets it. The following issues come up most often:

  • Type guessing: Spreadsheet programs may convert values automatically when they open a CSV. Leading zeros can be dropped, so the ZIP code 02134 can become 2134. Long identifiers may switch to scientific notation, and text that looks like a date may be turned into one. Importing with columns explicitly set to text avoids most of this.
  • Character encoding: CSV has no built-in way to declare its encoding. UTF-8 is a common choice, but a receiving program may guess a different encoding and garble accented or non-Latin characters. Some tools add a byte order mark to signal UTF-8, and some other tools then treat that mark as stray characters. Test the file in the destination you actually use.
  • Line endings: Files may use Windows-style or Unix-style line breaks. Most modern parsers accept both, but some strict or older tools do not.
  • Formula injection: A cell that begins with =, +, -, or @ may be treated as a formula when the file is opened in a spreadsheet. If the data comes from untrusted input, this is a known security risk, documented by OWASP as CSV injection. Sanitize or prefix such values before export when the file will be opened in a spreadsheet.
  • Styled Unicode text: If cells contain decorative characters, such as mathematical bold letters used as a "font", the export keeps them as distinct code points. They will not match ordinary letters in search, sorting, or deduplication. Convert them to plain characters first if those operations matter.

Accessibility depends on how the file is opened. A screen reader reading raw CSV in a text editor encounters a stream of values, commas, and quotation marks with no table structure. Opened in a program that renders the data as a grid, the same file can be navigated cell by cell. If people will read the data directly, a properly marked-up table or a summary in prose usually serves them better than the raw file. No specific screen reader or application was tested for this review, so the behavior of a particular combination needs to be confirmed on its own.

Gaps in this review

No specific export tool, spreadsheet application, or import destination was tested or documented for this article. The guidance above relies on general, verifiable properties of the format rather than measured results. Exact behavior depends on the program and its settings, especially for type conversion, encoding detection, delimiter defaults, and support for line breaks inside fields. Before relying on an export, round-trip a small sample that includes these elements and compare the result with the source:
• leading zeros
• commas and quotes inside fields
• multi-line notes
• non-ASCII characters