What is a CSV file

It is a text file with commas in it, and everything difficult about it comes from how little it says.

A comma-separated file is lines of text with commas between the values. There is no specification of what anything means, and that absence causes every problem associated with it.

A CSV opened in a text editor, showing the raw lines and the quoting.
A CSV opened in a text editor, showing the raw lines and the quoting.

What the file contains

code,product,price,updated
00742,Bracket,4.20,2026-09-14
00913,"Fixing kit, 6mm",11.90,2026-09-16

A header line, then rows. Values separated by commas.

Two rules beyond that. A value containing a comma is wrapped in quotes. A quote inside a quoted value is written twice. Those two rules are where most hand-written parsers fail.

That is the whole format. Nothing says which column is a number, a date, or a code that happens to look like one.

Why that causes damage

A spreadsheet opening the file has to decide what each value is, and it decides by pattern.

00742 looks like a number, so it becomes 742. The leading zero is gone and the product code no longer matches anything.

03/04/2026 looks like a date, and which date depends on the regional setting of whoever opened it.

123456789012345678 exceeds the precision of a stored number and comes back rounded.

+44 20 7946 starts with a plus, so it is read as a formula and produces an error.

None of that is the file's fault. The file said nothing, and something had to guess.

Value in the file What a spreadsheet does What it should be
00742 742 Text
03/04/2026 Ambiguous date Text, or year-first
123456789012345678 Rounded Text
+44 20 7946 Formula error Text

Writing dates so they survive

Year first, hyphens, four-digit year.

2026-09-14

Unambiguous in every country, sorts correctly as plain text, and understood by every tool. Any other format is asking the reader to guess, and half of them will guess differently from you.

Opening one without damage

Import rather than open. Every spreadsheet has an import route that presents a step where each column can be assigned a type.

Set anything that is a code, an identifier, a postcode or a phone number to text. Double-clicking skips that step, which is why double-clicking is the problem.

The same data published as a table on a page, with the file available underneath.
The same data published as a table on a page, with the file available underneath.

What to use instead

Between machines, JSON carries types. A number is a number, a string is a string, and nothing guesses.

To a person, a table on a page. They see the exact characters you published, on a phone, with no import step and no chance of their software reinterpreting anything.

Keep the file available underneath for anyone who wants to do arithmetic. That combination removes the most common way data gets corrupted between two people.

If this is near what you are doing, How to open a CSV file correctly and How to import a CSV into Google Sheets cover the cases on either side.

Put it at an address

Remember the file has no types, write dates year first, import rather than open, quote values containing commas, and publish a table when sending data to a person.

Then the codes that went in are the codes that come out.

Questions people ask

What is actually in the file?

Lines of text, with values separated by commas and the first line usually holding column names. That is the entire format.

Why do leading zeros disappear?

Because the file says nothing about what a value is. A spreadsheet reads 00742 and decides it is a number, and numbers do not have leading zeros.

Why do dates change?

Same cause. The file contains 03/04/2026 and nothing about which part is the month. Whatever opens it decides based on its regional setting.

What if a value contains a comma?

It is wrapped in quotes, and a quote inside a quoted value is doubled. That is where most hand-written parsers go wrong.

What should I use instead?

For data between machines, JSON carries types. For data to a person, a table on a page cannot be mangled by their software.

Keep reading