How to convert Excel to CSV without losing leading zeros
Why ZIP codes, phone numbers and IDs lose their zeros (or turn into 1.23E+11) between Excel and CSV, and how to stop it at every step.
You save a workbook as CSV, send it off, and the reply comes back: half the ZIP codes are four digits long, phone numbers have lost their leading zero, and a column of account numbers now reads 1.23457E+15.
Nothing was wrong with your data. The zeros get lost at one of two moments, and they need different fixes:
- When the CSV is created, if the value was stored as a number in Excel.
- When a CSV is opened in Excel, because Excel converts anything that looks like a number.
The second one is by far the more common, and it fools people into thinking the CSV is broken when it isn’t.
Check the CSV before blaming it
Open the CSV in a plain text editor: Notepad on Windows, TextEdit on Mac, or any code editor. Don’t use Excel. If you see 02134 there, the file is fine. Excel was dropping the zeros on display, and anyone importing the file into a database or script will get the right values.
If the text editor shows 2134, the zeros were lost when the CSV was made. Read on.
From experience: this check settles most “broken CSV” problems. It takes ten seconds, and it’s the first thing I ask for before anyone starts re-exporting files.
Creating the CSV: keep values as text
Excel can only write a leading zero if the cell actually holds one. A cell showing 02134 can do that in two ways:
- Stored as text. You see a small green triangle in the corner, and the value is left-aligned. The zero is part of the value and always survives.
- Stored as the number 2134, with a custom format like
00000. Excel displays the zero.
The good news: Excel’s Save As → CSV writes values the way they are displayed, so a custom number format is kept in the CSV. Both cases come out right, as long as you use Excel’s own Save As.
Zeros do get lost with scripts and some converters that read the underlying number and ignore the format. The Excel to CSV converter has a Use formatted values option, on by default, that writes what you see in Excel, the same way Save As does.
Fixing a column that’s already lost its zeros
If the cells really hold 2134, put the zeros back with a formula in a helper column:
=TEXT(A2, "00000")
Use as many zeros as the code should have digits: "000000" for a six-digit code. Then Copy → Paste Special → Values over the original column, so the result is stored as text.
Opening a CSV in Excel without losing zeros
Double-clicking a CSV lets Excel guess each column’s type, and it guesses “number” for anything that looks like one. Instead:
- Open a blank workbook.
- Go to Data → From Text/CSV and pick the file.
- In the preview, click Transform Data.
- Click the header icon of each code column and set the type to Text.
- Click Close & Load.
The zeros stay, and so do long numbers.
In recent versions of Microsoft 365 for Windows you can also switch the guessing off: File → Options → Data → Automatic Data Conversion, and untick Remove leading zeros and convert to a number. Then double-clicking a CSV keeps the zeros.
In Google Sheets, choose File → Import, upload the CSV, and untick Convert text to numbers, dates, and formulas.
The other trap: long numbers
From experience: this is the one I’d warn about first if you handle financial data. Unlike a lost leading zero, the original digits can’t be recovered from the saved file, so the only fix is the source system’s export.
Excel stores numbers with 15 significant digits. Anything longer, like a 16-digit card number or a long transaction ID, is silently rounded: the last digits become zeros, and the display switches to 1.23457E+15.
This damage is permanent once the file has been opened and saved as a number. The fix is the same as for leading zeros: treat the column as Text from the start, both when typing it and when importing a CSV.
Encoding: names with accents
If José or Müller turn into José or Müller, that’s an encoding problem, not a zeros problem. In the Save As dialog, choose CSV UTF-8 (Comma delimited) instead of plain CSV (Comma delimited). If an old version of Excel shows garbled accents when opening a UTF-8 file, tick Add UTF-8 BOM in the converter. The extra marker at the start of the file tells Excel which encoding to use.
A checklist for clean exports
- Store codes (ZIP, PIN, phone, account and product IDs) as text, not numbers.
- Export with CSV UTF-8.
- Check the result in a text editor, not by double-clicking it into Excel.
- When opening CSVs, import them with column types set, rather than double-clicking.
Need the file as JSON instead? The CSV to JSON converter has a Detect numbers switch. Turn it off and every value stays text, zeros included.