How to Keep Leading Zeros in a CSV File
Sending us a spreadsheet of card numbers, names or barcodes? Excel has a habit of turning 000123 into 123. The file looks fine, and the cards print the wrong number.
This guide shows how to save a CSV file from Excel with every leading zero in place, how to check it before you send it, and how to open it again without losing them. Using Google Sheets or Apple Numbers? See their steps.
The short versionFormat the number column as Text before you type or paste. Save the sheet as CSV UTF-8 (Comma delimited). Then check the file in NotepadTextEdit, not in Excel.
Why the zeros disappear
Excel reads 000123 as the number 123. A number has no leading zeros, so Excel removes them. It does this so it can add up and sort your figures.
A CSV file is plain text with no formatting. Microsoft says a CSV saves values as they are displayed in the cells. If a cell shows 123, the file says 123, and 123 is what gets printed.
Two danger pointsZeros go missing when numbers go into Excel, and again when a saved CSV is opened in Excel. The steps below cover both.
1Store the numbers as text
Do this before you type or paste the numbers. Changing the format afterwards won’t bring back zeros that have already gone.
- Click the letter at the top of your number column. The whole column is selected.
- On the Home tab, open the Number Format box. It usually says General. Choose Text.
- Or press Ctrl+1Cmd+1, choose Text on the Number tab and click OK.
- Type or paste your numbers.
Quick checkText sits on the left of the cell and numbers sit on the right. A small green triangle in the corner means Excel has spotted a number stored as text. That’s what you want here, so don’t choose Convert to Number.
Only a few numbers? Use an apostrophe
Type an apostrophe before the number, like '000123. Excel keeps it as text. The apostrophe shows in the formula bar, but not in the cell, and it isn’t saved in the CSV.
2Save as CSV UTF-8
CSV UTF-8 keeps the zeros you stored as text, and keeps accented names such as Zoë, José and Siân exactly as you typed them.
- Click File, then Save As. If you only see Save a Copy, use that. It appears when AutoSave is on.
- Choose where to save the file.
- Open the Save as type list and choose CSV UTF-8 (Comma delimited) (*.csv).
- Click Save.
- Click File, then Save As. If you only see Save a Copy, use that. It appears when AutoSave is on.
- Open the File Format list and choose CSV UTF-8 (Comma delimited).
- Choose where to save it, then click Save.
- One sheet only. A CSV holds just the sheet you’re looking at, so keep all your data on that sheet.
- A warning is normal. Excel may say some features might be lost. A CSV keeps your values and drops the formatting, so carry on and save.
3Check the file in NotepadTextEdit
A plain text editor shows exactly what’s in the file, so it’s the place to check it.
- Find the CSV file in File Explorer.
- Right-click it and choose Open with, then Notepad.
- Look at the first few lines. You should see 000123, not 123.
- Close it without saving.
- Find the CSV file in Finder.
- Control-click it and choose Open With, then TextEdit.
- Look at the first few lines. You should see 000123, not 123.
- Close it without saving.
Never do thisCheck the file by opening it in Excel. Excel normally strips the zeros as it opens the file, so a good file looks broken. Press Save at that point and the file really is broken.
Zeros already gone? Put them back
Formatting a column as Text won’t restore zeros Excel has already removed. If every number should have the same number of digits, one formula adds them back.
- Click an empty cell next to your first number and type this formula:
=TEXT(A2,"000000") - Change A2 to your first number cell. Use one 0 for each digit the number should have. Six zeros turn 123 into 000123.
- Double-click the small square at the bottom right of the cell. The formula fills down the column.
- Copy the new column. Right-clickControl-click the same cells and choose Paste Special, then Values. The formulas become plain text.
Different lengths?A formula can’t know how many zeros each number had. Go back to the original list and enter the numbers into a column formatted as Text.
Opening a CSV without losing the zeros
Double-click a CSV and Excel converts the numbers as it opens it. The zeros vanish from the screen, but they’re still in the file. Press Save now and they vanish from the file as well.
Card numbers longer than 15 digits
Excel stores numbers to 15 digits. Microsoft says any digit after the 15th is rounded down to zero, and uses a credit card number as its example.
Gift card and loyalty card numbers can run to 16 digits or more. Stored as a number, the last digit is lost for good. Stored as text, every digit is kept. Excel may also show a long number as 6.03455E+15, which is scientific notation. Text format stops that too.
Google Sheets and Apple Numbers
The rule is the same as in Excel. Set the number column to text before the numbers go in, save a CSV, then check it in a plain text editor. Apple says Numbers normally removes a leading 0 from a number, and formatting the cell as text stops that.
Google Sheets
- Click the letter at the top of your number column.
- Click Format, then Number, and choose Plain text.
- Type or paste your numbers. Keep all your data on one sheet.
- To save a CSV, click File, then Download, and choose Comma Separated Values (.csv).
Apple Numbers
- Click the table, then click the letter at the top of your number column.
- In the Format sidebar, click the Cell tab.
- Click the Data Format pop-up menu and choose Text.
- Type or paste your numbers. Keep all your data in one table.
- To save a CSV, choose File, then Export To, then CSV. Leave Include table names unticked, so the file holds only your rows. Click Save, choose where to save it and click Export.
Then check itOpen the CSV in NotepadTextEdit, as in step 3, not in a spreadsheet app. To change anything, change your original spreadsheet and save the CSV again.
Zeros already gone?
In Google Sheets, the TEXT formula above works the same way: =TEXT(A2,"000000"). Then copy the new column and use Edit, Paste special, Paste values only (Ctrl+Shift+VCmd+Shift+V). Numbers has no TEXT function, so there, enter the numbers again into a column formatted as Text.
Before you send your file
- Text format: the number column is formatted as Text, and the numbers sit on the left of their cells.
- One sheet: all the data is on the sheet you saved.
- File type: CSV UTF-8 (Comma delimited) from Excel, or a CSV from Google Sheets or Numbers.
- Checked: opened in NotepadTextEdit, the numbers show their leading zeros.
- Not re-saved: the CSV hasn’t been opened and saved in a spreadsheet app since you checked it.
Questions & Answers
-
Why does Excel remove the leading zeros from my numbers?
Excel treats 000123 as the number 123, and a number has no leading zeros. Format the column as Text before you type or paste, and Excel keeps them.
-
Can I use a custom number format like 000000 instead?
It can work. Microsoft says a CSV saves values as they are displayed, so 123 shown as 000123 should save as 000123. But the cell still holds 123, and numbers over 15 digits still lose digits. Microsoft suggests custom formats for data that stays inside the workbook. For a file you send to us, Text is the safer choice.
-
Notepad shows 000123 but Excel shows 123. Which is right?
Notepad, or TextEdit on a Mac. It shows exactly what is in the file. Excel converts the numbers as it opens the file.
-
Why is there a green triangle on my cells?
Excel is flagging a number stored as text. For card numbers that is what you want. Leave it, or select the cells and choose Ignore Error.
-
Should I choose CSV UTF-8 or CSV (Comma delimited)?
CSV UTF-8. Both keep leading zeros when the cells hold text, but UTF-8 also keeps accented letters and symbols correct. Microsoft notes that the older CSV format turns the euro sign into a question mark.
-
How do I keep leading zeros in Google Sheets or Numbers?
Set the number column to text before the numbers go in. In Google Sheets, choose Format, Number, Plain text. In Numbers, choose Text from the Data Format pop-up menu in the Cell tab of the Format sidebar. Then save a CSV and check it in Notepad or TextEdit.
-
Does this apply to phone numbers and barcodes?
Yes. Store anything that identifies something as text, and keep number formats for amounts you add up. UK mobile numbers starting 07 and barcodes starting with 0 lose the zero in the same way.
Not sure your file is right?
Ask us before you order. Tell us what the file is for and what your card numbers should look like.
Email sales@cpcards.co.uk. We often reply within minutes, 9am to 5pm, Monday to Friday.

