New Tool Radar

AI for Data & Spreadsheets

How to Preserve Leading Zeros When Importing a CSV Into Excel

Preserve leading zeros when importing a CSV into Excel so codes and postcodes stay intact.

Schematic with three steps: Import through the Text Import Wizard, not; Set the code column format to Text; Check the codes after import.

A product code of 00427 or a postcode of 01234 loses its leading zeros the moment Excel opens the CSV, because Excel reads the column as a number and drops the zeros. The code then fails every lookup against the system that issued it. Import the column as Text, so Excel keeps the characters exactly as they appear in the file.

What you need

  • The CSV file with codes that carry leading zeros
  • Excel with a blank workbook
  • A note of which columns hold codes, not numbers

Step 1: Import through the Text Import Wizard, not by double-clicking

Rename the file extension from .csv to .txt, or use Data, Get Data, Legacy Wizards, From Text (Legacy), so the Text Import Wizard runs and you can set the format of each column.

Step 2: Set the code column format to Text

In step 3 of the wizard, select the code column in the preview and choose Text as its column data format. Leave numeric columns as General, so they still calculate.

Step 3: Check the codes after import

After loading, read the first and last codes in the column and compare them with the file: the leading zeros must still be there, and the column must be left-aligned as text. Test one lookup against the source system.

Worked example: synthetic code list

The table below is a synthetic example. It shows the expected result of preserving leading zeros; no file was imported.

Check Value Result
Codes in the file 6 All start with 0
Codes after double-click open 6 Zeros dropped
Code 00427 after open 427 Leading zeros lost
Codes after Text import 6 Zeros kept
Code 00427 after Text import 00427 Matches the file

Expected result (UNTESTED). opening the file directly turns 00427 into 427, but importing the column as Text keeps all 6 codes intact, including 00427. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • A column imported as Text cannot be summed; convert it only if the values are really numbers.
  • Formatting a number column as Text after import does not bring the zeros back; the import must set Text.
  • Postcodes and product codes are identifiers, not quantities, so Text is the right format for them.
  • Some CSV exports strip the zeros before Excel ever sees the file; check the file in a text editor first.

Sources

See all