mygems

What a CSV file is, and how to open one without breaking it

A CSV file is a plain-text table: one line per row, commas between values. What is inside one, the five ways to open it, and why Excel mangles IDs and dates.

By mygems ·

A CSV file is a plain-text table. Each line is a row, commas separate the values in it, and the first line is usually the column names. There is no formatting, no formulas and no second sheet — which is exactly why almost every program can read one, and why opening one carelessly is the fastest way to damage the data inside it.

That second half is the part nobody warns you about. Double-click a CSV and Excel will quietly delete leading zeros, turn long IDs into 1.23E+15 and read 3-4 as the 3rd of April. The file on disk is fine until you save it. This guide covers what is actually inside a CSV, how to open one without that happening, and how to check afterwards that nothing changed.

What is inside a CSV file

Open one in a text editor and you see the whole format:

id,name,city,amount
1,Ada Lovelace,London,1200
2,"Hopper, Grace",New York,980
3,Alan Turing,"Wilmslow, Cheshire",1450

Four lines, four records — one header and three rows. Everything else follows from three rules:

  • A comma ends a value, a newline ends a row. Nothing else carries meaning.
  • Quotes protect a value that contains a comma, a newline or a quote itself. "Hopper, Grace" is one value, not two. A quote inside a quoted value is written twice: "6"" nails".
  • Everything is text. 1200 is not a number to the file; it is four characters. Whether it becomes a number, a date or a product code is decided by whatever opens it. That single fact causes most CSV problems.

What a CSV cannot hold: fonts, colours, column widths, formulas, multiple sheets, charts, or a note that says "this column is text, don't be clever". If you need any of that, you need XLSX instead.

Two details that surface later: the file has an encoding (UTF-8 today, but older exports are often Latin-1, which is why é can arrive as é), and the separator is not always a comma. Exports from a system set to a comma-decimal locale — much of Europe and Latin America — use a semicolon, because 1,50 already means one and a half. The extension stays .csv either way.

How to open a CSV file

Five routes, worst first, because the usual advice is the one that does the damage.

Double-clicking it in Excel. Fastest, and the only one that rewrites your data on the way in. Fine for a file of names and plain whole numbers. Not fine for IDs, postcodes, phone numbers, SKUs, dates or anything with a leading zero.

Excel, imported properly. Open Excel first, then Data → From Text/CSV, pick the file, and in the preview set the delimiter and the encoding. Before you load, use Transform Data and set the columns you care about to Text. That is the version that leaves your IDs alone — the full recipe is here.

Google Sheets. File → Import → Upload, then untick Convert text to numbers, dates and formulas. With that box clear, Sheets shows you the file as written. Leave it ticked and you get Excel's behaviour.

A browser viewer. For reading a file rather than editing it, the safest option is something that parses the CSV and shows it, without converting anything or uploading the file. The CSV viewer on this site runs entirely in the tab — it has opened a 1 GB file in about three seconds in desktop Chrome — and it never writes the file back, so there is nothing it can corrupt.

A text editor or the command line. The ground truth. head -5 data.csv shows you the real bytes, which settles the delimiter and the quoting question in a second. For something readable:

csvlook data.csv | head -20
duckdb -c "SELECT * FROM 'data.csv' LIMIT 10"

DuckDB is also the answer when the file is too big for a spreadsheet at all — it reads a multi-gigabyte CSV without loading it into memory.

On a phone

A CSV usually arrives as an email attachment, and the phone has no spreadsheet waiting for it. iOS will preview small CSVs in Quick Look and hand bigger ones to Numbers, which imports them with the same type guessing Excel does.

CSV File Viewer - Smart CSViPhone & iPad · Android

Opens the whole file on iPhone or Android, then lets you search it, filter it visually, or query it with SQL when you need to be exact.

What it does

Platform specifics — which apps can do what, and the Files app route — are in the iPhone and iPad guide and the Android guide; the viewer's own documentation lives at smartcsvapp.com.

What goes wrong, and why

Every one of these is a type guess the file never asked for.

  • Leading zeros vanish. 00123 becomes 123, and postcode 01234 becomes 1234. The opener decided the column was numeric.
  • Long IDs change. Excel keeps 15 significant digits, so a 16-digit order number or credit-card-length value is rounded and shown as 1.23E+15. The last digits are gone, not hidden.
  • Codes become dates. 3-4 reads as 3 April, SEP1 as a September date, 1/2 as a day in January. Gene names are the famous case; part numbers are the common one.
  • Accents turn into mojibake. Müller arrives as Müller when a UTF-8 file is read as Latin-1, or the other way round.
  • Everything lands in one column. The file is semicolon-separated and the opener assumed commas. Set the delimiter on import; in Excel you can also put sep=; on a line of its own at the top of the file.
  • A row splits in two. A value contains a real newline inside quotes and something read the file line by line instead of parsing it. This is also why wc -l is not a row count.

The pattern: nothing errors. You get a file that looks plausible, and the damage is only visible if you go looking for it.

Check that nothing changed

Thirty seconds, before you send the file anywhere:

  1. Count the rows. The row count after opening should match the file, minus the header. A number that drops means rows were merged or dropped.
  2. Look up one record you know. Pick an ID with a leading zero or sixteen digits and read it in the opened file. If it is right, the typing was right.
  3. Scan the columns that should not be dates. Version numbers, part codes, ratios and anything with a dash or a slash.
  4. Keep the original. Copy the file before opening it in anything that can save over it. A damaged CSV cannot be recovered from its own saved version.

If a check fails, nothing is lost yet — the original file still holds the real values. Re-import it with the column set to text and the damage never happens.

Editing one, rather than reading it

Reading a CSV and editing one are different jobs with different risks. A viewer cannot damage a file it never writes. An editor has to write the file back, which means it has to be careful about quoting, encoding and line endings — the three things a spreadsheet export usually gets wrong.

CSV Editor - Smart CSViPhone & iPad

Edits cells on iPhone and iPad and saves every row back, using the delimiter, header and encoding it detected when it opened the file.

What it does

If the file is already damaged — mismatched quotes, rows of different lengths, half a line at the end — that is a repair job rather than an opening job, and fixing a broken CSV is its own guide.

Questions

What does CSV stand for?
Comma-separated values. The file is plain text: one row per line, commas between the values, and quotes around any value that contains a comma or a newline.
Is a CSV file the same as an Excel file?
No. A CSV holds only values, which is why every program can read one. An XLSX file holds formatting, formulas, multiple sheets and the type of each cell, and only spreadsheet software can read it.
Why does my CSV open with everything in one column?
The file uses semicolons rather than commas, which is normal in locales that write 1,50 for one and a half, and the program assumed commas. Set the delimiter when importing, or put a line reading sep=; at the top of the file for Excel.
Why did Excel delete the zeros at the start of my IDs?
Excel decided the column was numeric, and 00123 as a number is 123. Nothing in a CSV says a column is text, so import the file with Data → From Text/CSV and set that column to Text instead of double-clicking the file.
How do I open a CSV file without Excel?
Google Sheets imports one for free, any text editor shows the raw file, a browser-based viewer opens large ones without uploading them, and csvlook or DuckDB read them on the command line at any size.
Can I open a CSV file on my phone?
Yes. iOS previews small CSVs and opens larger ones in Numbers; dedicated CSV apps on iPhone and Android open the whole file without converting values, which matters for IDs and dates.

mygems — Builds CSV Editor and Smart CSV Viewer, two apps that exist because spreadsheets guess at what a CSV means.