How to Keep Leading Zeros When Saving Excel Data as CSV
Question details
The user needs to prevent Excel from dropping leading zeros (such as in zip codes or ID numbers) when copying data and saving it as a comma-delimited CSV file.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Exporting a worksheet or selected data containing numeric strings with leading zeros into a CSV format without losing the zeros.
- Observed behavior
- When saving as CSV, or when reopening a saved CSV file in Excel, the application interprets the data as standard numbers and automatically strips away the leading zeros.
Determine the exact character length your numeric strings should have (e.g., 4 or 5 digits) so you can correctly configure the text formulas before exporting. Additionally, ensure you have a basic text editor like Notepad ready to inspect the raw CSV output.
Format Values Explicitly as Text Using Formulas
Convert your numbers to text strings using the RIGHT or TEXT function before saving to ensure the leading zeros are permanently embedded in the CSV output.
Simply changing the cell format to 'Text' may not physically alter existing numeric data. Using a formula ensures the data is explicitly converted to text strings with the correct number of zeros before exporting.
Create a new blank column next to the data that requires leading zeros.
In the first cell of the new column, enter the formula =RIGHT("0000"&A1, 4) (replace A1 with your target cell and adjust the zero count and total length to match your data needs).
Drag the fill handle down to apply the formula to all relevant rows in the dataset.
Select the newly calculated column, press Ctrl+C to copy, right-click the original data column, and select 'Paste as Values' to remove the formula and keep only the text output.
Go to File > Save As, choose 'CSV (Comma delimited)' from the format dropdown, and save the file.

Verify CSV Output in a Text Editor
Confirm whether the leading zeros were actually dropped during export or simply hidden by Excel when reopening the CSV.
Import CSV Using Power Query or Text Wizard
Prevent the application from automatically dropping leading zeros when importing or reopening an existing CSV file.
Keep Leading Zeros Intact with WPS Spreadsheet
WPS Spreadsheet provides powerful formatting tools and a straightforward Text Import Wizard, making it incredibly easy to handle CSV files, control data types, and preserve formatting like leading zeros without hassle.
- 1. Open WPS Spreadsheet: Launch WPS Office and open a new blank spreadsheet.
- 2. Import the CSV file: Go to the Data tab, click on 'Import Data', and select your CSV file.
- 3. Use the Text Import Wizard: Follow the wizard prompts until you reach the column data format step.
- 4. Set column to Text: Select the column containing the leading zeros and choose 'Text' as the column data format before completing the import.

Frequently Asked Questions
Why does Excel automatically remove leading zeros from my CSV files?
CSV files are plain text files that do not store formatting rules. When Excel opens a CSV, it automatically interprets any value containing only digits as a standard number. In standard mathematics, leading zeros have no value, so Excel optimizes the display by stripping them out.
Can I format cells as 'Text' before typing to keep the zeros?
Yes. If you highlight a column and change its format to 'Text' from the Home tab before you start entering data, the application will treat any input as text and retain the leading zeros. However, when saving to CSV, you must still ensure that reopening the file is done via a data import wizard to prevent the zeros from being hidden again.
How can I add leading zeros to existing numbers that have already lost them?
You can restore them using the TEXT function. For example, if you need all values to be 5 digits long (like a US zip code), type =TEXT(A1, "00000") in an adjacent cell. This will append the necessary leading zeros to the front of any number shorter than 5 digits.




