Working with CSV files without breaking them
7 min read · Updated 23 October 2026
What is a CSV file, and why does it break so easily? CSV stands for "comma-separated values". It is a plain text file with one record per line and fields separated by commas, so any program can read it. The trouble is that there is no single strict rule for quotes, delimiters, encodings or dates, and spreadsheet programs often "helpfully" change what they think a value means. Open and save a CSV in the wrong way and ZIP codes lose their leading zeros, long ID numbers lose digits and codes turn into dates. The CSV editor opens CSV and TSV files with automatic delimiter detection and treats fields as text.
This guide explains what is inside a CSV file, the five problems that cause most damage, how to open files safely in Excel and Google Sheets, and how to fix a file that is already damaged.
What a CSV looks like inside
A CSV is just text. This is a complete file with a header row and two records:
customer,zip,phone,order_total
Ann Lee,02134,617-555-0142,"1,250.00"
Raj Patel,10001,212-555-0177,89.50
The first line names the columns. Each following line is one record. Notice the order total "1,250.00" is wrapped in quotes, because the number contains a comma. Without quotes, a program would see five fields on that row, not four.
The format is described informally in RFC 4180, which also registers the text/csv type. It is a description of common practice, not a law, so programs differ in small ways. That is where most problems start.
Problem 1: quotes, commas and line breaks inside fields
A field that contains a comma, a double quote or a line break must be wrapped in double quotes. Any double quote inside it is doubled:
name,comment
Ann,"Said ""hello"", then left"
This is one record with two fields: Ann and Said "hello", then left. Splitting that line on every comma gives the wrong number of columns. Use a real CSV parser, not a quick split. Every tool in this guide uses one.
A quick check for a broken file: count the fields in every row. If most rows have 4 fields and a few have 5, an unquoted comma is the likely cause.
Problem 2: not every CSV uses commas
In many European locales, spreadsheets write semicolons between fields, because the comma is the decimal separator (1,5 means one and a half). Tab-separated files (TSV) are also common, and some systems use the pipe character |.
Signs of a delimiter problem are that everything lands in column A, or that two columns appear merged. The CSV editor detects the delimiter from the content. If columns look wrong, check the preview and pick the delimiter yourself.
Problem 3: encodings
Modern files should be UTF-8. Older exports, especially from Windows programs, may be Windows-1252. Read a Windows-1252 file as UTF-8 and "José" shows up as "José" or with replacement symbols. The reverse mistake happens too.
Some programs add an invisible byte-order mark (BOM) at the start of a UTF-8 file. It is harmless to most software, but a program that does not expect it may show a strange character at the start of the first column name, or fail to match a column called id. Excel for Windows often needs the BOM before it reads UTF-8 correctly. If you save from Excel, choose CSV UTF-8 (Comma delimited) instead of plain CSV so accented letters survive.
Problem 4: what Excel changes when you open a CSV
If you double-click a CSV and Excel opens it, Excel guesses a data type for each column and converts the values on screen. If you save over the file, the changes become permanent.
| Value in the file | What Excel may show or save | Why |
|---|---|---|
02134 (ZIP code) |
2134 |
Treated as a number, so leading zeros go |
007 (product code) |
7 |
Same |
1234567890123456 |
1.23457E+15, saved as 1234567890123450 |
Excel keeps only 15 significant digits |
3-4 |
4-Mar |
Read as a date |
1/2 |
2-Jan |
Read as a date |
12E3 |
12000 |
Read as scientific notation |
Long IDs, such as 16-digit account or tracking numbers, are especially risky. Digits after the 15th are replaced with zeros, and you cannot get them back from the saved file. This is also the reason that genetics researchers saw gene names such as SEPT2 and MARCH1 turn into dates, which led the gene naming committee to rename some genes in 2020.
Excel also has a size limit: 1,048,576 rows per worksheet. A larger CSV opens only up to that row, with no warning in some versions, and saving it back would permanently cut the rest.
How to open a CSV in Excel without changes
- Open a blank workbook. Do not double-click the CSV.
- On the Data tab, choose From Text/CSV (on a Mac, it is under Data, then Get Data, then From Text/CSV).
- Pick the file. Check that the file origin says UTF-8 and the delimiter is correct.
- Choose Transform Data. In the Power Query window, select the columns that must stay exact (ZIP, phone, ID) and set their type to Text.
- Choose Close & Load.
How to open a CSV in Google Sheets
- In a blank sheet, choose File, then Import, then Upload.
- In the import dialog, set the separator type and turn off Convert text to numbers, dates, and formulas.
- Choose Import data.
On iPhone and Android, the Excel and Sheets apps open a CSV and apply their own guesses. For a file you must not alter, use a tool that treats every field as text, such as the CSV editor.
Problem 5: dates
Is 03/04/2026 March 4 or April 3? In the US it is March 4 (month first). In most of the world it is April 3 (day first). Nothing in the file says which. A column that also contains 25/12/2026 must be day first, because there is no month 25.
The safest format to store is ISO 8601: 2026-03-04 (year, month, day). It sorts correctly as text and is read the same way everywhere. The date-column normalizer uses evidence across a whole column to decide, converts mixed dates to one format, and flags rows it cannot decide for you to check.
Spreadsheet formulas in CSV files
Because a CSV is text, a field that starts with =, +, - or @ may be treated as a formula when it is opened in a spreadsheet. If you export data that includes text typed by outside users, such as form responses, this can be abused to run formulas on whoever opens the file. A common defense is to put a single quote or a space in front of such values when exporting. If you receive a file like this from an unknown source, view it in a text-based editor first.
Cleaning up a file
Once the file is in a safe tool, common cleanup jobs include:
- Removing duplicate and empty rows and trimming extra spaces. The data cleaner counts every change it makes so you can check the effect.
- Standardizing case, true/false values and blanks in a column so filters work.
- Merging several CSVs with matching columns, or splitting a big one into smaller files by row count or by the values in a column, with the CSV merge and split tool. This helps with files too large for Excel's row limit.
- Comparing two versions of a sheet to find added, removed and changed rows with the spreadsheet compare tool.
Converting between formats
Need Excel or JSON instead? The CSV, Excel and JSON converter converts in any direction between CSV, TSV, XLSX and JSON, with options for the sheet, delimiter and JSON shape. Formulas in spreadsheets are exported as their last calculated values, because CSV and JSON have no concept of formulas. Nested JSON is flattened into columns.
A short checklist before you trust a CSV
- Open it in a text-based viewer first and look at the first 10 lines.
- Check the delimiter and the number of columns on every row.
- Check the encoding: do names with accents look right?
- Check that ID, ZIP and phone columns still have their leading zeros and full length.
- Check that dates are unambiguous, ideally ISO format.
- Keep the original file untouched and work on a copy.
FAQ
Why does Excel remove the zero at the start of my ZIP codes?
Excel reads 02134 as the number 2,134 and drops the leading zero. Import the file with that column set to Text, or use a tool that keeps every field as text.
How do I open a CSV without losing leading zeros? In Excel, use Data, then From Text/CSV, and set the column to Text. In Google Sheets, turn off the conversion option when importing.
What is the difference between CSV and XLSX? CSV is plain text with no formatting, formulas or multiple sheets. XLSX is a spreadsheet file that stores all of those. CSV is more portable. XLSX keeps more information.
Why do accented letters look wrong in my CSV? The file was saved in one encoding and opened in another, usually Windows-1252 versus UTF-8. Reopen it with the correct encoding, or save as CSV UTF-8.
Can a CSV file have more than 1 million rows? Yes, a CSV file has no row limit. Excel does: 1,048,576 rows per sheet. Use a CSV editor or split the file into parts.
Why are all my columns in column A? The delimiter is not what the program expected, often a semicolon or tab instead of a comma. Import with the correct delimiter.