Skip to main content
MyDataFixer

How to Keep Leading Zeros in Excel CSV Files (Opening a CSV)

By the MyDataFixer team · Updated

The short answer

When Excel opens a CSV file, it sees 00123 and thinks it is the number 123, so it drops the zeros. The CSV file itself still has them, as long as you don't save over it. To keep the zeros, open the file so the column is read as text instead of as a number.

Why Excel removes the zeros

A CSV file is plain text, so it has no way to say “this column is a code, not a number”. When you double-click a CSV, Excel looks at every value and decides what it is. Anything made of digits becomes a number. And for a number, zeros at the start mean nothing: 00123 and 123 are the same amount. So Excel shows 123.

For amounts and quantities that is fine. But many values only look like numbers. They are really codes, and every digit matters.

Where this matters

  • Product codes, customer numbers and order numbers (00123)
  • PIN codes and postal codes (011001)
  • Phone numbers saved without a country code (09876543210)
  • Bank sort codes, employee IDs and invoice numbers

Example

The same values: in the CSV file, and after double-clicking it in Excel
In the CSV fileShown by Excel
00123123
01100111001
098765432109876543210

If you now save the file from Excel as CSV, the zeros are really gone: the new file contains 123, not 00123. That is why the most important rule is: don't save over the original after double-clicking it.

Long numbers have a similar problem

Excel stores at most 15 digits of a number. If a value is longer, like a 16-digit card number or a long ID, Excel changes the extra digits to zeros, and it may show the number in a short form such as 1.23457E+15. The fix is the same as for leading zeros: open the column as text.

Fix it in Excel

These steps are for Excel on a Windows or Mac computer. The Excel app on phones and tablets doesn't have these menus; on a phone, use Google Sheets or MyDataFixer instead.

Method 1: open the file without changing any values

  1. Open a new, empty workbook.
  2. Go to Data → From Text/CSV and choose your file.
  3. Check that the preview shows the right columns. If not, change Delimiter.
  4. Set Data Type Detection to Do not detect data types.
  5. Click Load. Every value is shown exactly as it is in the file, zeros included.

Method 2: choose text only for the code columns

  1. In the same window, click Transform Data instead of Load.
  2. Click the small icon at the left of the column name (for example “123”) and choose Text.
  3. If Excel asks, choose Replace current. Then click Close & Load.

This keeps amounts as numbers, so you can still add them up, while codes stay as text.

Fix it in Google Sheets

  1. Go to File → Import → Upload and choose the file.
  2. Untick Convert text to numbers, dates and formulas.
  3. Click Import data. The zeros stay.

To type a new code with a leading zero in Google Sheets, select the column first and choose Format → Number → Plain text.

Fix it with MyDataFixer

Open the CSV in CSV to Excel and download the Excel file. MyDataFixer decides for each value whether it is safe to turn into a number:

  • Values with leading zeros stay text, so 00123 stays 00123.
  • Numbers with more than 15 digits stay text, so nothing is rounded.
  • Plain amounts such as 12.50 become real numbers you can add up.

Because the result is an Excel file, not a CSV, Excel doesn't guess again when you open it: the zeros are kept every time. The summary tells you how many values were kept as text and why. It works on phones and tablets too, and your file stays on your device.

Typing codes with zeros in Excel

  • Type an apostrophe first: '00123. The apostrophe isn't shown in the cell.
  • Or select the column, right-click → Format Cells → Text, then type the codes.

How to avoid losing zeros next time

  • Never double-click a CSV with codes. Open it with Data → From Text/CSV, or convert it to an Excel file first.
  • Ask for an Excel file. If someone sends you data regularly, an .xlsx file keeps text columns as text.
  • Format code columns as Text before typing or pasting into them, in your own sheets.
  • Check after saving. Open a saved CSV in a text editor such as Notepad. If you see 00123 there, the zeros are safe, whatever Excel shows.

Quick summary

Excel drops leading zeros because it thinks codes are numbers. The CSV file still has them until you save over it. Open the file as text with From Text/CSV in Excel or Import in Google Sheets, or turn it into an Excel file with CSV to Excel, which keeps the zeros for good.

Common mistakes

  • Adding zeros back by hand. It's easy to add the wrong number of zeros. Open the original file again instead.
  • Using a number format with zeros. A custom format like 00000 makes 123 look like 00123, but the cell still holds 123. When saved as CSV, the zeros may disappear again.
  • Opening and saving in a hurry. If Excel asks whether to keep the CSV format, the zeros may already be gone. Keep the original.

Fix it in your browser

Free, no sign-up. Your file is processed on your device and never uploaded.

Questions and answers

Are the zeros gone from my CSV file?

Not unless you saved the file from Excel. Open the original again with one of the methods above.

How do I type a number with a leading zero in Excel?

Type an apostrophe first ('00123), or format the cells as Text before typing.

Why do long numbers like card or ID numbers change?

Excel keeps only 15 digits of a number and changes the rest to zeros. Open such columns as text.

Will my amounts still work if I open everything as text?

Text can't be added up. Open only the code columns as text (Method 2), or use CSV to Excel, which keeps plain amounts as numbers.

Does MyDataFixer upload my file?

No. The file is converted in your browser, on your device.