🧹 Data Cleaning · 8 min read
CSV Files Lose Formatting After Save: Leading Zeros, Dates, Long Numbers
A CSV file stores characters, not formats. When you save a workbook as CSV, the spreadsheet writes out the value it displays and throws the number format away, which is why 00123 reopens as 123 and a 16-digit reference comes back with a zero on the end. The digits are usually still in the file. What changed is the set of rules used to read them.
This is not a bug in Excel, Google Sheets or LibreOffice, and there is no setting that turns it off, because the format was never designed to carry presentation. Knowing exactly what crosses the boundary makes the fix obvious: protect the value on import, or stop using CSV for that column.
What Actually Gets Written
RFC 4180 defines a CSV as records of fields separated by commas, where a field may be wrapped in double quotes if it contains a comma, a quote or a line break. That is the whole specification. There is no field type, no locale, no number format, no colour, no column width.
Microsoft states the consequence plainly in its own documentation for saving workbooks: when you save in .csv or .txt format, formatting, graphics and other objects are lost. What survives is the text of each cell as it would be displayed, joined by the list separator.
So the file is a faithful record of what you saw. The ambiguity appears on the way back in, when a program has to decide whether 00123 is a number, a product code, or a nine-digit phone fragment, and it has no evidence beyond the characters.
| Cell in the sheet | What the CSV contains | What reopens |
|---|---|---|
| 00123 (text or zero-padded) | 00123 | 123 |
| 4111 1111 1111 1111 | 4111111111111111 | 4.11111111111111E+15 |
| 03/04/2026 (3 April) | 03/04/2026 | 4 March on a US locale |
| £1,250.00 | 1250 or £1,250.00 | Depends on the writer |
| 12.5% (stored 0.125) | 12.5% | Text, not a number |
The Four Failures People Actually Report
1. Leading zeros
Postcodes, SKUs, employee numbers and phone fragments lose their padding because the reader infers a number. The fix has to happen at import time. In Excel, use Data then From Text/CSV and set the column type to Text before loading; in Power Query the same choice appears as a column type of Text. In Google Sheets, open the import dialog and turn off the option to convert text to numbers and dates, then format the column as Plain text.
An apostrophe typed in front of the value works inside the sheet and dies on save: the apostrophe is a display prefix, so the CSV receives the digits and the next program repeats the guess.
2. Long numbers
Excel holds 15 significant digits of precision. A 16-digit card, IMEI or tracking number exceeds that, so the stored number is rounded and the last digit becomes 0, or the column switches to scientific notation. Nothing in the CSV is wrong; the conversion is lossy. Set the column to Text on import, or keep identifiers as strings with the last digits intact.
3. Dates
There is no date type in CSV, only the string the writer chose. Excel writes the date in the short-date format of the machine that saved the file, and reads it back using the locale of the machine that opens it. Send a file from London to New York and 03/04/2026 changes meaning without any error.
Use ISO 8601, 2026-04-03, for anything that crosses a border or a system boundary. It sorts correctly as text, it is unambiguous, and every importer recognises it.
4. Currency, percentages and thousand separators
Depending on the writer, 1250.5 or 1,250.50 or £1,250.50 arrives in the file. Only the first parses cleanly everywhere; the second breaks a comma-delimited file outright, and the third arrives as text in most tools. Export a raw number column and handle the presentation in the report.
Why Quoting Does Not Help
It is a reasonable guess that wrapping a value in quotes tells the reader to keep it as text. It does not. RFC 4180 quoting is a container for commas, quotes and line breaks; it says nothing about type. A quoted "00123" is read by Excel as 123 exactly like an unquoted one.
The Excel-only trick ="00123" does survive a round trip inside Excel, because the cell holds a formula that returns text. It also writes the equals sign and quotes into the CSV, so pandas, SQL loaders and CRM importers receive a literal string with punctuation attached. Use it only when the file never leaves Excel.
Fixes That Survive a Round Trip
| Situation | What actually works |
|---|---|
| Humans will reopen it and edit it | Keep .xlsx as the working copy; export CSV only for machines |
| Identifiers with leading zeros | Import as Text (From Text/CSV, column type Text; Sheets: Plain text) |
| Dates shared across locales | Write YYYY-MM-DD and never anything else |
| Cards, IMEIs, VAT numbers | Text column, full stop; never a number format |
| Code that reads the file | Read everything as string, then cast deliberately |
In pandas, read_csv(path, dtype=str, keep_default_na=False) makes every column text and stops the empty-string-to-NaN conversion at the same time. That single line removes most of the silent damage in a data pipeline, at the cost of casting the numeric columns yourself a moment later.
If the file is produced by a script you control, write the identifiers with their padding and keep the schema next to the file. A one-line README saying which columns are text prevents the next person from opening the export in Excel and saving it back.
Check What Is Actually in the File
Before you rebuild anything, open the CSV in a plain text editor such as Notepad, VS Code or TextEdit in plain-text mode. Look for the leading zeros in the raw bytes. If they are present, the file is fine and the problem is entirely on the import side; if they are absent, the export already lost them and the sheet needs fixing first.
Two quick checks catch most cases: the number of fields per line should match the header, and the first data row should look like the values you typed rather than what the spreadsheet displayed. A parser that reports field counts per row will find both problems in seconds.
Frequently Asked Questions
Why does Excel remove leading zeros when I open a CSV file?
Because a CSV has no cell formats to read. Excel infers the type from the characters and treats 00123 as the number 123. The digits are still in the file; they are reinterpreted on import.
Why do the last digits of a 16-digit number turn into zeros?
Excel keeps 15 significant digits, so a longer number is rounded during conversion. Import the column as Text, or store identifiers as strings from the start.
Why do dates change when the file is opened on another computer?
The writer used its own short-date format and the reader applies its own. Store dates as YYYY-MM-DD to remove the ambiguity entirely.
Does quoting a field keep it as text?
No. Quoting exists so a field can contain commas, quotes and line breaks. It is not a type declaration.
What format should I use if formatting matters?
.xlsx for anything a person will edit and look at. CSV for interchange, bulk import and version control, where plain text is an advantage rather than a limitation.
See What Your File Really Contains
Paste the export and get row counts, column counts, empty fields and type drift before the values reach anyone who trusts them.
Related reading
Data Cleaning — other guides that pair well with this one.
- Fix Garbled CSV in Excel
- Keep Leading Zeros in CSV
- Empty CSV File: Fixing pandas 'No columns to parse from file'
- CSV Column Mixed Types: Why pandas Turns Numbers Into Text
Browse all guides in the NoCodeCSV blog.