Why CSV Files Break And What They Never Tell You
A quoted value may contain a line break. It is also the one thing most simple parsers get wrong, and mail exports produce it as a matter of course.
A CSV file never tells you how to read it. Not the delimiter, sometimes called the separator, not the quoting, not the character set, not the line endings. Four decisions were made when the file was written. None of them was recorded anywhere. Every program opening it has to guess all four.
That is the whole problem and the reason the format survives anyway. Nothing else is as easy to produce. Almost every mail export, contact list and report ends up in one.
The CSV Specification With No Authority
There is a document. RFC 4180 sets out what a CSV should look like. What kind of document it is matters more than what it says.
It was published to write down what software already did rather than to tell anybody what to do. Its own text describes the format as one that has been in use for years without any formal specification. It makes no attempt to change that.
Compare that with how mail is specified. RFC 5322 says a message line ends with two particular characters and every mail server obeys. RFC 4180 says a CSV field may be enclosed in quotes and a great deal of software does whatever it likes. One is a rule, the other is a description of a habit.
The Four Things a CSV File Never Records
Every CSV carries four unstated decisions. A reader has to work out each one. Getting any of them wrong changes what the data appears to say.
-
The separatorNot always a commaSemicolons across much of Europe, because the comma is the decimal separator there. Tabs and pipes turn up too -
The quotingHow a value containing a separator is protectedDouble quotes by convention. A quote inside a quoted value is written twice. Some software escapes with a backslash instead -
The encodingNothing declares itExcel guesses a regional default rather than UTF-8, which is why accented names arrive as symbols -
The line endingsBoth conventions in useUsually harmless. It matters the moment a value contains a line break of its own
The same program writes different files on different machines. A spreadsheet exporting a CSV follows the regional settings of the computer it is running on. Two colleagues export the same sheet. One gets commas and the other semicolons. Neither has done anything unusual.
The Quoting Rule That Breaks Simple CSV Parsers
A quoted value may contain a line break. That is explicitly permitted. It is also where most hand written CSV handling falls over.
subject,from,body
"Invoice query","sam@example.net","Hello,
Could you check the March invoice?"
"Site access","jo@example.org","Confirmed for Tuesday."
Split that on line breaks and you get five records, three of them nonsense. Parse it properly and you get three rows, one of which contains a body with a blank line in the middle of it.
This is exactly what a mail export produces. Message bodies contain line breaks by their nature, so any export putting bodies in a column produces the awkward case as a matter of course rather than as an edge case. A CSV of messages is the hardest kind of CSV there is.
Read next Line Endings And the Two Bytes That Break Things One of the four decisions. Also the one that turns a value into two rows.What Happens When Mail Becomes a CSV File
Exports to CSV are common in mail work. The format is a poor fit for what mail contains.
| What a message holds | What a CSV can do with it |
|---|---|
| A body with paragraphs | One quoted value containing line breaks |
| Several recipients | One value with a separator inside it, quoted |
| Three attachments | Filenames at best. The files cannot travel |
| Formatting and inline images | Nothing. Both are lost |
| Headers and routing | Only the columns somebody chose to include |
| A reply threading a conversation | A row, with no relationship to any other row |
The last two rows are where people are surprised later. A CSV of messages is a report about mail rather than a copy of it. It cannot be turned back into mail afterwards.
Use it for what it is good at. A list of who wrote to whom and when, for reading in a spreadsheet, is a reasonable thing to want and CSV does it well. Keeping the mail itself needs a format built for messages, which is any of the ones built to hold them.
What Excel Does to a CSV File Without Asking
Most complaints about broken CSV files are complaints about a spreadsheet trying to help.
| Your value | What arrives | Why |
|---|---|---|
| 00745 | 745 | Read as a number, so the zeros went |
| 3-4 | 4 March | Read as a date |
| 1234567890123456 | 1.23457E+15 | Too long, shown in scientific notation |
| SEPT1 | 1 September | A gene name, read as a date |
| Jose with an accent | Odd symbols | The encoding was guessed wrongly |
None of these damages the file. The CSV on disk still holds what you wrote. The spreadsheet changed the display. The damage only becomes permanent if somebody saves over the original from that view. Opening through the import dialogue rather than by double clicking lets you set each column as text and avoid all of it.
Making a CSV File Somebody Else Can Open
- Use commas and quote generously. Wrap any value holding a comma, a quote or a line break. Quoting a value that did not need it costs nothing and breaks nothing.
- Write UTF-8. Add the byte order mark where Excel is the reader. That single choice removes the accented character problem in the place it happens most.
- Put a header row on it. Nothing requires one and every recipient wants one. It is the only thing in the file that explains itself.
- Say what you did. Separator, encoding, quoting, in the email or the filename. The file cannot state its own terms, so somebody has to.
- Send JSON when software is the reader. Types and structure are stated rather than guessed, so none of the four questions arises.
The filename is a fair place to put it. Something ending in utf8-semicolon tells the next person more than any amount of explanation they will have deleted by the time they open the file.
Where a CSV has arrived and nobody knows how it was written, reading it before importing it saves the guesswork. Our CSV viewer shows the columns as a parser actually splits them rather than as a spreadsheet redraws them. The converters handle the route between a mailbox and a table when a report is what you need.
Format rules checked against RFC 4180 in August 2026. The export behaviour described was reproduced in a current spreadsheet program.
Questions People Ask
7 questions, answered in full below.Is there a CSV standard?
There is a published description called RFC 4180. It carries no authority. It records habits that were already in place. Nothing in it obliges anybody. The document is open about that. Software follows it loosely or not at all.
Why does my CSV open in one column?
The reader guessed the wrong separator. A file using semicolons opened by something expecting commas finds no columns to split on, so every row becomes one long value. The data is intact and the import settings are what need changing.
Why do some CSV files use semicolons?
Because in much of Europe a comma marks the decimal point, so a file full of prices would be ambiguous. Spreadsheet software in those regions writes semicolons instead. The same program on a different machine writes commas.
Can a value contain a line break?
Yes, inside quotes. The specification permits it outright. It is also the single thing most simple parsers get wrong, because splitting on line breaks first seems obvious and it destroys any row containing one.
Why does Excel mangle my data?
Because it tries to be helpful with values it recognises. Leading zeros disappear from reference numbers. Things resembling dates get reformatted. Long digit strings turn into scientific notation. None of that is a fault in the file.
What should I use instead?
JSON where software is reading it, since the types and the shape are declared rather than inferred. CSV remains the right answer when a person has to open the file in a spreadsheet, which is most of the time and the reason it survives.
How do I make a CSV that others can open?
Commas. Quotes around anything holding a comma or a line break. UTF-8, marked at the front where Excel is involved. A header row. Then say which conventions you used somewhere the recipient will see, because the file cannot.
Sources
Where the figures and behaviour described above were checked.
- Common Format and MIME Type for CSV Files IETF, RFC 4180
- Comma-separated values Wikipedia
- Tab-separated values Wikipedia