Keep Leading Zeros in Excel CSV Imports and Exports
If 00123 becomes 123 when you open a CSV, or the zeros seem to disappear again after saving, check the file before changing its formatting. The source text and the values Excel displays can differ.
Decide whether the value is an identifier
Ask what a calculation on the column would mean. Adding two SKUs usually has no useful interpretation, while adding quantities does. That is why this sample needs different types in adjacent columns: sku is text and quantity is numeric.
Leading zeros may distinguish records. A supplier could use both 00123 and 123 as separate codes, or use a mixture of code lengths. Converting those values to numbers can collapse distinct identifiers. Do not infer a universal five-character rule just because the first few examples happen to be that length.
| Purpose | Store as | Consequence |
|---|---|---|
| Exact SKU 00123 | Text | All five characters remain meaningful |
| Quantity 4 | Number | Can be summed with quantity 8 |
| Display number 123 as 00123 | Number with custom format 00000 | Underlying value is still 123 |
| Rebuild a verified five-digit code | TEXT formula result | Creates text using the known width |
Import CSV into Excel without losing leading zeros
Start with the original CSV, not a CSV resaved after zeros disappeared. These steps keep the sample SKU as text while allowing quantity to remain numeric.
If the query already contains a Changed Type step that made sku numeric, remove that conversion and assign the types again from the unconverted source. Changing the already shortened value back to Text would only produce the text 123. Load the table and compare both SKUs character for character with the file.
- In a new desktop Excel workbook, choose Data > From Text/CSV and select the original file.
- Confirm the delimiter. For this sample, choose Comma and check that sku and quantity occupy separate columns.
- If Data Type Detection is available, turn detection off so values initially remain text. Choose Transform Data.
- In Power Query, select sku and set its data type to Text. Set quantity to Whole Number.
- Choose Close & Load, then confirm the two SKUs are 00123 and 00456.
Use formatting only for its intended job
For new manual entry, select the empty destination range and choose Text in Format Cells before typing the codes. For a few manually entered values, an initial apostrophe is another Excel entry method. That entry convention is not a general CSV type declaration.
A custom number format such as 00000 changes the display of a numeric value. It can make 123 appear as 00123 in the worksheet, but it does not prove that the original code contained exactly two leading zeros. Use a real text identifier when another table, export, or lookup must receive the exact code.
Related help: Protect IDs with 16 or more digits from Excel conversion
Rebuild only a documented fixed width
Suppose a supplier confirms that every SKU consists of exactly five digits and the remaining digits are intact. In a helper column, TEXT can then apply that known rule. This is a reconstruction from a specification, not recovery of hidden characters. Keep the original shortened column until you have checked the rebuilt values.
Do not use a formula that blindly takes the last five characters; it can truncate a legitimate longer code. Investigate any input longer than the required width, negative value, decimal value, or non-digit character before padding.
If A2 contains numeric 123:
=TEXT(A2,"00000")
Expected text: 00123
If A3 contains numeric 456:
=TEXT(A3,"00000")
Expected text: 00456
Use only when five digits is the confirmed source rule.Why do leading zeros disappear after saving as CSV?
After import, use ISTEXT(A2) to check the SKU type and compare A2 with the original 00123. A type check alone would also accept the wrong text 123, so it is not a value check. Confirm the second code as well and verify that quantities total 12.
A reopened worksheet is not enough evidence that the export lost its zeros. Open the saved CSV in a plain-text editor, locate the sample SKU, and follow the matching case below. Keep a working .xlsx copy when you need workbook formatting; CSV does not store an instruction that the next reader must treat a column as Text.
| What the saved CSV actually contains | What that establishes | Next step |
|---|---|---|
| 00123,4 | The source characters survived this export | Import sku as Text when reopening |
| 123,4 | This saved copy no longer has the original width | Return to an intact export; do not guess padding |
| No original source, but a confirmed five-digit rule | The width can be reconstructed from the rule | Use the conditional TEXT example above |
Stop automatic zero removal in Excel 365 or 2024
In Microsoft 365 or Excel 2024, Windows users can open File > Options > Data; Mac users can open Excel > Preferences > Edit. Under Automatic Data Conversion, disable the option that removes leading zeros.
Reopen an intact sample to check the result. This preference does not govern Power Query imports; keep their column types explicit. If the option is absent, use the import procedure above.
Know what a leading-zero warning establishes
Column Harbor can flag digit strings that may be at risk during spreadsheet import. The warning means the values deserve an explicit type decision; it does not mean the CSV itself is broken. The checker cannot restore zeros already removed from a saved file or assign Excel column types.
Common questions
Will quoting "00123" in CSV preserve it as text in Excel?
Quotes describe CSV field boundaries, not an Excel cell type. Choose Text during import instead of relying on quotes to prevent automatic conversion.
Can Excel recover zeros after I save the changed file?
If the saved value is only 123 and there is no original source or reliable width rule, the previous number of zeros cannot be determined from that value alone.
Does this work for ZIP codes, phone numbers, and account codes?
Yes, when the values are identifiers, preserve their exact characters as Text. Do not pad all of them to five digits: phone numbers, international postal codes, and account codes can follow different length rules. Keep quantities and other measures numeric.
Sources & method
- Microsoft Support: Keeping leading zeros and large numbers ↗
- Microsoft Learn: Power Query Text/CSV connector ↗
- Microsoft Support: Add or change data types (Power Query) ↗
- Microsoft Support: TEXT function ↗
- Microsoft Support: IS functions ↗
- Microsoft Support: Format numbers as text ↗
- Microsoft Support: Set automatic data conversions ↗
- Microsoft Support: Import or export text (.txt or .csv) files ↗
Examples and diagrams use synthetic data. Application instructions follow the linked documentation; available menus and options can vary. Our sample checks do not establish behavior in every Excel or Google Sheets version. Read our AI-assisted editorial method.