Practical guide

How to preserve leading zeros in CSV and Excel

Keep postcodes, account numbers and identifiers from being silently converted to numbers.

Leading zeros are a type problem

The string 00123 and the number 123 are different data. CSV has no type metadata, so spreadsheet software guesses. Double-clicking a CSV often converts 00123 to the number 123 before you can intervene.

Import CSV instead of opening it

Use the spreadsheet application’s data-import command, choose UTF-8 and mark identifier columns as Text. The CSV-to-XLSX tool on this site also writes imported cells with text formatting and does not execute formula-like values.

Example: a Canadian postal routing code 00705 should remain five characters. Importing the column as text retains 00705; numeric import produces 705.

Export with an explicit contract

When another system consumes the file, document which columns are strings. JSON can preserve 00123 only when it is quoted as a string; a numeric JSON value cannot carry leading zeros.

Verify edge cases

Check the first and last rows, empty identifiers, long account numbers and values that resemble dates. Scientific notation can damage identifiers even when leading zeros are not present.

Use the relevant tools

CSV to XLSX · XLSX to CSV · XLSX to JSON

These guides are general information, not legal, security or records-management advice. Follow your organisation’s policies for sensitive files.