In this guide
Preserve CSV leading zeros by importing identifier columns as text before Excel converts them into numbers. A code such as 000742 must keep its original characters: it is an identifier, not a quantity.
Example verification: These are synthetic examples with expected results. The steps have been reviewed against documentation but not yet tested in Excel.
For identifiers, the safest approach is to import the original CSV and explicitly treat those columns as text before numeric conversion occurs.
Practice with a harmless sample
Create a plain text file named sample.csv with these invented values:
ItemCode,PostalCode,Reference,Quantity
000742,00128,987654321012345678,3
009005,02005,000123456789012345,8
The first three columns should remain exactly as written. Quantity should be a number. This test catches both lost zeros and the precision issue with long identifiers.
Make a backup of your original CSV before opening or editing it.
Method 1: Preserve CSV Leading Zeros with Power Query
These instructions apply to desktop Excel versions with the Get & Transform data tools; interface details vary.
- Open a blank workbook instead of double-clicking the CSV.
- On the Data tab, choose From Text/CSV (under Get Data if necessary), select the original CSV and inspect the preview.
- If the preview offers a data-type detection option, select the option not to detect data types automatically. Make sure the delimiter separates the four columns correctly.
- Choose Transform Data to open Power Query Editor. Inspect Applied Steps and remove or adjust any automatic Changed Type step that has converted an identifier to a number. You must still have access to the original strings.
- Set ItemCode, PostalCode and Reference to the Text data type. Set Quantity to Whole Number. Replace the existing incorrect type-change step rather than converting already-damaged values to text.
- Select Close & Load to load the table to Excel.
Microsoft describes using Power Query to preserve these kinds of fields as text during import [1]. This approach is useful for recurring exports because the conversion steps can be refreshed.
Method 2: Check Excel’s automatic conversion settings
Some recent desktop Excel versions include Automatic Data Conversions settings. In supported Windows versions, look under File > Options > Data. If available, disable the conversion that removes leading zeros and the conversion that truncates long numeric strings. Microsoft documents availability for Microsoft 365 and Excel 2024, including Mac versions with their corresponding settings interfaces [1, 2].
Do not rely on this setting for older versions or for all colleagues’ computers. Explicit text-column import is a more controlled workflow when handling a mixed dataset. For versions with the legacy Text Import Wizard, specifying Text for each identifier column is another option [3].
Check the result before saving
Use these checks for the sample’s first data row in A2:C2:
| Check | Expected result |
|---|---|
| =ISTEXT(A2) | TRUE |
| =LEN(A2) | 6 |
| =EXACT(A2,”000742″) | TRUE |
| =EXACT(B2,”00128″) | TRUE |
| =EXACT(C2,”987654321012345678″) | TRUE |
The last check is particularly important because numeric values in Excel have a limit of 15 significant digits [1]. A longer identifier must remain text to preserve every digit.
Confirm that Quantity still contains numbers, not text, so that calculations work normally.
Why a custom number format is not the same solution
A custom format such as 000000 can display the number 742 as 000742. However, the stored value is still a number. That can be appropriate for a known fixed-width display requirement, but it does not prove that the original file contained six characters or that those characters will survive another import.
If the original width is known, =TEXT(A2,”000000″) can create a six-character text representation from a valid short numeric code. It cannot recover arbitrary missing zeros when the original width is unknown, or restore digits that were already lost from a long number. Return to the unmodified source in those cases.
Save and reopen without losing the values again
Save the working workbook as XLSX so that Excel can preserve the cell types. If another system requires a CSV, export a separate copy and inspect the resulting file in a plain text editor. Verify that every original identifier and digit is present. A CSV does not store Excel cell-type metadata; reopening it by double-clicking may trigger automatic conversion again. Reimport using explicit text columns whenever you need to examine it in Excel.
Find the first step that changed an identifier
Open the untouched CSV in a plain text editor next to the Power Query preview. Compare one short code with leading zeros, one full-length identifier and one ordinary quantity. If the file contains 000742 and a preview shows 742, step backward in Applied Steps until the full string reappears. Change the data type at that point. Adding a Text step after the numeric conversion would only turn 742 into the text “742”.
If the raw file itself says 742, the import has no evidence of the missing characters. Ask for the original export or confirm a fixed width against the source system’s specification. A postal code, account reference and stock quantity can all look numeric in a CSV while requiring different rules. Preserve CSV leading zeros in the fields whose characters identify a record and convert only fields intended for arithmetic. [1]

Audit a fresh export before handing it off
Use the second sample row as a regression check after you refresh. The expected identifiers are 009005, 02005 and 000123456789012345. The two quantities should total 11. That gives you checks at both ends of the import: the codes still match exactly, and the column used for calculation still behaves like a number.
For regular deliveries, keep a small fixture containing a leading-zero ID, a long identifier, a blank and a known quantity. Write down what blank means to the receiving system before treating it as zero or filling it. Compare the number of records and the control total each time the upstream export changes. If a delimiter change shifts an identifier into the quantity column, the shape or total should make you stop before delivery.
When the destination needs CSV, inspect the saved text as well as the workbook. Write down which columns downstream users must import as text. Quoting around a CSV field is part of CSV syntax. It doesn’t communicate the spreadsheet data type to every importer. If exact identifier characters are missing in the saved file, return to the workbook and investigate the export rather than distributing it. [3]

Sources
[1] Microsoft Support, Keeping leading zeros and large numbers: https://support.microsoft.com/en-us/excel/keeping-leading-zeros-and-large-numbers
[2] Microsoft Support, Data import and analysis options in Excel: https://support.microsoft.com/en-us/excel/data-import-and-analysis-options-in-excel
[3] Microsoft Support, Import or export text files: https://support.microsoft.com/en-us/excel/get-started/import-or-export-text-txt-or-csv-files



