To prevent Excel from removing leading zeros when opening a CSV file, you must format the data as text before importing—Excel automatically converts numeric-looking values, stripping zeros. This ensures values like 00123 or 01-045 remain intact for accurate data handling, especially in IDs, ZIP codes, or product codes.
What You'll Need
- A CSV file containing values with leading zeros
- Microsoft Excel (any recent version: 2016, 2019, 2021, or Microsoft 365)
- Access to the Windows File Explorer or macOS Finder
Step-by-Step
- Open the folder containing your CSV file. Do not double-click the file yet.
- Open Excel first—launch the application from your Start menu, Applications folder, or desktop shortcut.
- In Excel, go to the Data tab on the ribbon.
- Click Get Data > From Text/CSV. This opens the file browser.
- Navigate to and select your CSV file, then click Import.
- In the preview window that appears, look at the column headers and data samples. Identify which columns contain leading zeros (e.g., ZIP codes, product IDs, phone numbers).
- Click on the column header of each column that should preserve leading zeros. A dropdown arrow will appear.
- From the dropdown, select Data Type > Text. Repeat this for every such column. Do not leave any column as Automatic or Whole Number.
- Once all relevant columns are set to Text, click Load at the bottom of the preview window.
- Excel will import the data with leading zeros preserved. The values will appear exactly as they were in the CSV, including
007,01234, or0-001. - Save the Excel file as an .xlsx file to retain the formatting. If you re-export as CSV later, leading zeros will still be preserved in the Excel file but may be lost again if you reopen the original CSV without using this import method.
Common Mistakes
- Double-clicking the CSV file directly in File Explorer or Finder—this causes Excel to open it with auto-formatting enabled, stripping leading zeros immediately.
- Using Open instead of Get Data > From Text/CSV—this bypasses the data-type selection step.
- Setting only one column to Text while ignoring others that also contain leading zeros—this results in partial data loss.
- Assuming that changing cell formatting after import will fix the issue—Excel has already converted the value to a number, so formatting as text afterward cannot restore the zeros.
- Renaming the file extension from .csv to .txt and opening it—this does not prevent Excel from auto-converting values upon import.
Tips
- Always use Get Data > From Text/CSV instead of double-clicking—this is the most reliable method across all Excel versions.
- If your CSV contains mixed data (numeric and text), use the preview window to manually assign data types before loading. This avoids future errors.
- For recurring imports, save your Power Query steps as a query. Go to Queries & Connections in the Data tab, right-click your query, and select Properties to name and reuse it later.
- Use a prefix like an apostrophe (
') in the CSV file itself (e.g.,'00123)—this forces Excel to treat it as text when opened directly. However, this method is not recommended for automated workflows, as it alters the source data. - Test your import with a small sample file first. Create a CSV with one row containing
001,002,003to verify the method works before processing large datasets. - When sharing the Excel file, ensure recipients know it was imported properly—otherwise they may reopen the original CSV and lose the zeros again.
Troubleshooting
- Leading zeros still disappeared? You likely opened the file by double-clicking. Close Excel completely, then follow the Get Data > From Text/CSV steps again.
- Excel shows an error when loading? Check that your CSV is properly formatted: use commas as delimiters, not tabs or semicolons. If your region uses semicolons, change the delimiter in the import wizard under Advanced settings.
- Some columns are grayed out in the preview? This means Excel couldn’t detect data in them. Open the CSV in a text editor (like Notepad++) to verify the values exist and that the column structure is consistent across all rows.
- Power Query won’t let me change data type? Make sure you’re clicking the column header in the preview window, not the table header. If the column is blank in all rows, Excel may not recognize it as text—add a sample entry with a leading zero to force detection.
- After saving as .xlsx, reopening the original CSV still removes zeros? That’s expected. The fix only applies to the import process. Always use the same import method every time you open the CSV.
Frequently Asked Questions
Why does Excel remove leading zeros from CSV files?
Excel treats values that look like numbers (even with leading zeros) as numeric data by default. It strips zeros because they’re mathematically insignificant in numbers like 007 or 0123. This is automatic behavior to optimize data handling, not a bug.Can I fix leading zeros after importing the file?
No. Once Excel converts a value to a number, the original formatting is permanently lost. You cannot restore leading zeros by changing cell formatting. The only solution is to re-import using the correct method.Does this work on Mac Excel too?
Yes. The steps are identical on macOS Excel. Go to Data > Get Data > From Text/CSV, then set column types to Text in the preview window before loading.What if my CSV uses a different delimiter, like semicolons?
In the import preview window, click Advanced and change the delimiter from comma to semicolon (or tab, pipe, etc.). Excel will re-parse the file correctly before you assign data types.Can I use a formula to add back leading zeros after import?
You can use=TEXT(A1,"00000") to pad values to a fixed length, but this only works if the original number is still present (e.g., 123 instead of 00123). It won’t restore lost zeros. Prevention via proper import is always better.