mygems

How to stop Excel changing your CSV data

Excel strips leading zeros, turns IDs into 1.23E+15 and codes into dates the moment it opens a CSV. Here is how to import it so nothing changes.

By mygems ·

Double-click a CSV and Excel "helps". Postcode 01234 becomes 1234. Order number 4012888888881881 becomes 4.01289E+15, and the last digit is replaced with a zero. Product code 3-5 becomes the 3rd of May. None of this is in the file. Excel did it on the way in, and if you save, it becomes permanent.

The fix is not to open the file differently each time and hope. It's to stop Excel guessing, which takes about a minute.

The fast answer

  • Don't double-click the CSV. Use Data → From Text/CSV and set the fragile columns to Text before loading.
  • On Microsoft 365, turn off the conversions you don't want under File → Options → Data → Automatic data conversion.
  • Never save over the original after opening it the double-click way. The damage is written into the file at that moment.
  • Google Sheets: File → Import, and untick Convert text to numbers, dates, and formulas.

What Excel changes, and why

A CSV has no types: every value is text. Excel wants numbers and dates, so it guesses, column by column, cell by cell. The guesses that hurt:

You hadExcel showsWhat happened
012341234Leading zero stripped from a "number"
40128888888818814.01289E+15Scientific notation; digits past the 15th become 0
3-5, 1/25-Mar, 2-JanRead as a date
MARCH1, SEPT21-Mar, 2-SepRead as a date (a famous problem for gene names)
1E5100000Read as scientific notation
=1+12Read as a formula
TRUETRUE (as a boolean)Usually harmless, until it's a name

Two of these are destructive rather than cosmetic. Scientific notation on a 16-digit number throws away the last digit, because Excel stores numbers with 15 significant digits. And a value read as a date is stored as a date serial number. Change the format back to text and you see a serial number like 46086, not 3-5.

The moment that matters is Save. Opening a CSV changes what you see. Saving it as CSV writes what you see back into the file, and the original values are gone.

Fix 1: import instead of opening

This works in every desktop version of Excel from 2016 on.

  1. Open a blank workbook.
  2. Data → From Text/CSV, and pick the file.
  3. In the preview, click Transform Data (not Load).
  4. In Power Query, select each fragile column: IDs, postcodes, phone numbers, product codes, account numbers. Then Transform → Data Type → Text. If it asks, choose Replace current.
  5. Close & Load.

The values arrive exactly as written. You can still do arithmetic on the genuinely numeric columns, because you only switched off the guessing where it hurt.

If you'd rather have the old wizard: File → Options → Data → Show legacy data import wizards → From Text (Legacy). It then appears under Data → Get Data → Legacy Wizards, and step 3 of the wizard lets you mark columns as Text.

Fix 2: turn off automatic conversion

Recent Excel for Microsoft 365 has settings for exactly this, under File → Options → Data → Automatic data conversion:

  • Remove leading zeros and convert to a number
  • Keep the first 15 digits of long numbers and display in scientific notation
  • Convert digits surrounding the letter "E" to a number in scientific notation
  • Convert continuous letters and numbers to a date

Untick the ones that bite you. There is also an option to be notified when Excel converts something while opening a CSV, which is worth leaving on: it turns a silent change into a visible one.

These settings apply to double-click opening too, which makes them the most convenient fix. They're also the least portable: the person you send the file to has their own settings.

Fix 3: Google Sheets and Numbers

Google Sheets converts by default, too. Use File → Import → Upload, and in the import dialog untick Convert text to numbers, dates, and formulas. Everything arrives as text, exactly as written.

Numbers on Mac and iPhone also strips leading zeros and reads date-like values as dates. Select the column and set its format to Text to stop it for new entries, but the conversion on open has already happened. If the data matters, check a few known values against the raw file.

Fixes that look clever and aren't

  • Wrapping values as ="01234" in the CSV. Excel shows 01234. Every other tool reading the file sees a formula, and so does the next system your export goes into.
  • Adding an apostrophe, '01234. Same problem: the apostrophe is now part of your data everywhere except Excel.
  • Formatting the column as Text after opening. Too late. The zero is already gone; formatting can't bring it back.

On a phone

Phones have the same problem with fewer settings. Numbers on iPhone and the Sheets and Excel apps all convert on open, and a CSV re-saved from them carries the changes.

A CSV app that treats every cell as text doesn't have this problem, because it never converts. In Smart CSV Viewer you can still tell a column it holds numbers, currency or dates, so it sorts and filters correctly, but the type only changes how the column is displayed. The text in the file stays as it was.

The Column type sheet for a Budget column set to Number shown as currency, with the note that the file keeps its text as it is
A display type, not a conversion
CSV File Viewer - Smart CSViPhone & iPad · Android

Shows a column as a number, currency or date without rewriting it, so leading zeros, long IDs and codes stay exactly as the file has them.

What it does

A habit worth having

Before you trust any CSV round trip through a spreadsheet, check three values that are easy to break: one ID with a leading zero, the longest number in the file, and one code that looks like a date. If those three survived, the rest almost certainly did. The CSV vs XLSX guide covers why this happens with every spreadsheet, not only Excel.

Questions

How do I stop Excel from removing leading zeros in a CSV?
Don't open the CSV by double-clicking it. Use Data → From Text/CSV, choose Transform Data, set the affected columns to Text, then load. On Microsoft 365 you can also untick 'Remove leading zeros and convert to a number' under File → Options → Data → Automatic data conversion.
Why does Excel change long numbers to 1.23E+15?
Excel stores numbers with 15 significant digits and shows long ones in scientific notation. Digits past the 15th are replaced with zeros, so a 16-digit ID is permanently changed if you save. Import the column as Text to keep every digit.
How do I stop Excel turning numbers into dates in a CSV?
Import the file with Data → From Text/CSV and set the column to Text, or on Microsoft 365 untick 'Convert continuous letters and numbers to a date' in the automatic data conversion settings. Changing the format afterwards doesn't help, because the value has already been stored as a date.
Can I get my leading zeros back after saving the CSV?
Not from the saved file: the zeros are gone from it. If the values had a fixed length, you can pad them back with a formula such as TEXT(A2, "00000"), but the reliable fix is to re-export from the source system and import it properly.
Does Google Sheets change CSV data too?
Yes, by default. Use File → Import and untick 'Convert text to numbers, dates, and formulas' to keep every value as text.

mygems — Builds CSV Editor and Smart CSV Viewer, two apps that exist because spreadsheets give up on big files.