35 years' experience and customer care, printing since 1992
all our plastic cards are proudly printed in England Proudly printed in England all our plastic cards are proudly printed in England
Tel 01948 411 867 Email: sales@cpcards.co.uk We often reply within minutes 9-5 Mon-Fri

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.

Show steps for
Cell to card Format: Text
Formatted as General, the zeros drop off and the card prints 123. Formatted as Text, they stay.

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.

The same number typed into two columns. Only the column formatted as Text reaches the CSV with its zeros.

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.

Select the column, then choose Text in the Number Format box. New numbers keep their zeros and sit on the left of the cell.
  1. Click the letter at the top of your number column. The whole column is selected.
  2. On the Home tab, open the Number Format box. It usually says General. Choose Text.
  3. Or press Ctrl+1Cmd+1, choose Text on the Number tab and click OK.
  4. 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.

The apostrophe stays in the formula bar. The cell, and the CSV, get 000123.

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.

Choose CSV UTF-8 (Comma delimited) from the file type list, then save.
  1. Click File, then Save As. If you only see Save a Copy, use that. It appears when AutoSave is on.
  2. Choose where to save the file.
  3. Open the Save as type list and choose CSV UTF-8 (Comma delimited) (*.csv).
  4. Click Save.
  1. Click File, then Save As. If you only see Save a Copy, use that. It appears when AutoSave is on.
  2. Open the File Format list and choose CSV UTF-8 (Comma delimited).
  3. 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.

Opened in a plain text editor, the CSV shows every zero.
  1. Find the CSV file in File Explorer.
  2. Right-click it and choose Open with, then Notepad.
  3. Look at the first few lines. You should see 000123, not 123.
  4. Close it without saving.
  1. Find the CSV file in Finder.
  2. Control-click it and choose Open With, then TextEdit.
  3. Look at the first few lines. You should see 000123, not 123.
  4. 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.

TEXT pads each number to six digits. Paste Special, Values then turns the results into plain text.
  1. Click an empty cell next to your first number and type this formula: =TEXT(A2,"000000")
  2. Change A2 to your first number cell. Use one 0 for each digit the number should have. Six zeros turn 123 into 000123.
  3. Double-click the small square at the bottom right of the cell. The formula fills down the column.
  4. 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.

Opening a CSV by double-clicking converts the numbers. Importing it as text keeps them.
Switch off the conversionMicrosoft 365 and Excel 2024. Go to File, Options, Data and find Automatic Data Conversion.Go to Excel, Preferences (or Settings), Edit and find Automatic Data Conversion. Untick the option that removes leading zeros.
Import it as textGo to Data, From Text/CSV and pick the file. Set Data Type Detection to Do not detect data types, then click Load.Go to Data, Get Data (Power Query) and choose Text/CSV. Set the number column to Text before you load it.
Choose Don’t ConvertNewer versions of Excel may ask whether to convert the data as a CSV opens. Choose Don’t Convert and the zeros stay.

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.

Stored as a number, the 16th digit becomes 0. Stored as text, every digit is kept.

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.

Plain text in Google Sheets, Text in Numbers. Either way the card numbers keep their zeros.

Google Sheets

  1. Click the letter at the top of your number column.
  2. Click Format, then Number, and choose Plain text.
  3. Type or paste your numbers. Keep all your data on one sheet.
  4. To save a CSV, click File, then Download, and choose Comma Separated Values (.csv).

Apple Numbers

  1. Click the table, then click the letter at the top of your number column.
  2. In the Format sidebar, click the Cell tab.
  3. Click the Data Format pop-up menu and choose Text.
  4. Type or paste your numbers. Keep all your data in one table.
  5. 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.

Not sure what you need? Ask us