Skip to content

Why Excel removes leading zeros from a CSV, and how to keep them

Excel turns a code such as 00123 into the number 123, though the CSV still holds the zeros. OpenAnyDoc's CSV viewer keeps every cell as written, and CSV to Excel keeps such codes as text.

By OpenAnyDoc ·

The short answer

Excel turns a code such as 00123 into the number 123 when it opens a CSV, because it treats anything that looks like a number as a number. The zeros are still in the CSV file; only Excel's copy loses them. To keep them, import the column as Text instead of double-clicking the file, or open the CSV in a viewer that keeps every cell as written.

Why Excel removes leading zeros

Microsoft's page on keeping leading zeros and large numbers (checked 30 November 2026) says Excel removes leading zeros so that formulas and maths work on the values. The same page says Excel keeps at most 15 significant digits, so a longer ID number has every digit after the 15th turned into a zero.

  • Postcodes, phone numbers, employee and product codes lose their first zeros.
  • Card numbers, national ID numbers and long order numbers end in zeros.
  • Saving the CSV again from Excel writes the shortened values back to the file.

Keep the zeros in Excel: import the column as Text

Microsoft's steps, in short:

  • Open a blank workbook and choose Data, then From Text/CSV, and pick the file.
  • In the preview, choose Edit (or Transform Data) to open the query editor.
  • Select the column with the codes, then set its data type to Text and choose Replace current.
  • Choose Close & Load. The codes arrive as text, zeros included.

Two quicker fixes, and their limits

Microsoft's page also gives these:

  • Type an apostrophe before a number ('00123) and Excel keeps it as text. That works for typing, not for a file of thousands of rows.
  • A custom number format such as 00000 shows a five-digit postcode with its zeros. The page warns that it does not bring back zeros that were already removed, and the value underneath is still a number.

Read the file without losing anything

To check what a CSV really contains, open it in the CSV viewer. Every cell is kept as text exactly as written, so 00123 and a 19-digit ID show as they are, on screen and in the file you download. The separator and the encoding are detected, and Arabic shows right to left.

If you need an Excel workbook, CSV to Excel builds one in your browser: plain numbers become numbers, while values with a leading zero, values that start with + and IDs longer than 15 digits stay text. The file is not uploaded.

Related problems

If the whole row lands in one column, the separator is the problem: see why a CSV opens in one column. If Arabic turns into symbols, see why a CSV shows broken Arabic text in Excel.

Questions?

Write to support@openanydoc.com and describe what you need (no personal data).