How to Keep Leading Zeros When Importing a CSV into Excel
Bring ZIP codes and product IDs into Excel with every digit intact. Check the original CSV, choose the right column type and verify the saved result.
Follow these steps at your own pace. Check product terms and prices directly with providers before purchasing.
Quick answer
In desktop Excel for Windows, open a blank workbook and choose Data → From Text/CSV. Pick the file, select Transform Data and set the ID column to Text before loading it. If Power Query offers Replace current, use it to replace the automatic type conversion.
1. Check what the CSV actually contains
Open the original CSV in a plain-text editor such as Notepad. Find an identifier you recognize, for example 00127. Leave the file unchanged. If the original already reads 127, the import cannot tell whether the correct code was 127, 0127 or 00127. Get a fresh export or confirm the required code length before attempting a repair.
2. Import from a blank workbook
Start Excel and open a blank workbook. On the Data tab, choose From Text/CSV. If needed, look under Get Data → From File. Select the CSV and click Import. In the preview, make sure the field names have separate columns. If the whole line sits in one column, pick the delimiter used in your file. Choose Transform Data.
3. Set the type at the point where the digits still exist
Click the ID column heading in Power Query. Open the data type menu beside the heading and choose Text. If asked, select Replace current. Confirm the column shows the ABC symbol and the full code. Keep quantities and prices numeric.
If the preview still shows 127, inspect Applied Steps on the right. Click the step immediately before Changed Type. If 00127 reappears there, remove the automatic Changed Type step in this new query, then assign Text to the ID column and recheck the types of the other columns. Converting an already shortened value to text cannot recover the digits.
| What you see | What to check |
|---|---|
| 00127 with LEN equal to 5 | The five characters survived. |
| 00127 with LEN equal to 3 | A display format may be padding the number 127. |
| 127 in the original CSV | Check the upstream export. |
4. Load and test a known record
Choose Home → Close & Load. If the first code is in A2, enter =LEN(A2) in a spare cell. The code 00127 should return 5. Check another code with a different number of starting zeros, then save the working copy as an Excel workbook (.xlsx).
Why the zeros may disappear again
CSV files carry plain fields without Excel’s column-type settings. Opening an exported CSV by double-clicking it can trigger a fresh conversion. Inspect the export in a text editor and use the import steps again when you need to work with it in Excel.
Microsoft Support · Keeping leading zeros and large numbers
Comments
Read or join the discussion.