Excel removes leading zeros because it converts a value such as “000742” into the number 742 when it treats the cell or CSV column as numeric. To keep the zeros, store the column as text before the value enters the sheet: format the cells as Text before typing, or set the column type to Text when you import the CSV, instead of opening the file with a double-click.
For invoice data, this is not cosmetic. A supplier item code is an identifier, even when it contains only digits, and Peppol defines the seller’s item code as an identifier, not a quantity. Treat “000742”, “0000742” and “742” as three different strings until a supplier document says otherwise. The same rule belongs in your invoice data validation before import: check the characters of every code, not only the amounts.
Why does Excel remove leading zeros?
Excel stores numbers, not the characters you typed. When a cell or an imported column is numeric, “000742” becomes the value 742 and the zeros are gone from the stored value. Three related conversions hit invoice codes for the same reason:
- Long references. Excel’s number precision is commonly limited to 15 significant digits. Stored as a number, a 17-digit reference such as
12345678901234567typically has its last digits replaced by zeros and may appear in scientific notation; the test set below checks this in your own version. - Scientific-looking codes. A code such as
1E10can be read as 10,000,000,000. - Date-looking codes. A code such as
03-04can become a date under some import rules.
CSV does not prevent any of this. RFC 4180 defines records, fields, commas and quotes; it declares no column type. Quoting a field ("000742") protects commas inside it, but does not tell the spreadsheet to keep the value as text. The receiving application decides when it opens the file.
How do you keep leading zeros in Excel?
Pick the method by where the value comes from. Only the first three keep the original characters; the last two rebuild or imitate them.
| Situation | Method | Keeps the original characters? |
|---|---|---|
| Typing or pasting codes | Format the column as Text before entering values, or type an apostrophe first ('000742) | Yes |
| Importing a CSV or text file | Use the Data tab’s text/CSV import, choose the delimiter, set the code column to Text before loading (if the import dialog offers no column type, do it in the query editor) | Yes |
| Importing through the spreadsheet’s query editor | Set the column type to Text before any automatic type-detection step converts it | Yes, if no earlier step changed it |
| Codes already stored as numbers, known fixed width | =TEXT(A2,"000000") in a new column | Only if the width is verified for that supplier |
| Display only | Custom number format 000000 | No: the stored value is still 742 |
Steps for a supplier CSV:
- Keep an untouched copy of the file.
- Open a blank workbook and start the text/CSV import rather than double-clicking the file.
- Select the delimiter, then mark every identifier column (item code, supplier reference, PO number, invoice number) as Text.
- Leave quantities and amounts numeric; they need their own checks.
- Load, then compare the test codes below with the source.
InvoiceLineLab extracts invoice line items from PDF to Excel or CSV and writes item codes as text, with the source page beside each row, so a code such as 000742 reaches the sheet with its zeros. You can check the structure in the synthetic example.
What goes wrong when invoice codes lose their zeros?
The totals still add up, which is why the error survives review. Take this fictional vendor (supplier) invoice in USD:
| Line | Item code on the PDF | Quantity | Unit price | Line net |
|---|---|---|---|---|
| 1 | 000742 | 4 | 12.50 | 50.00 |
| 2 | 0000742 | 2 | 8.00 | 16.00 |
| 3 | 742 | 10 | 1.10 | 11.00 |
| Total | 77.00 |
Imported as text, the three codes stay distinct and product 742 carries $11.00. Imported as numbers, all three become 742: filtering or summing by code 742 now returns three rows and $77.00, while the invoice total is still $77.00. Quantity × price is right on every line (4 × 12.50 = 50.00; 2 × 8.00 = 16.00; 10 × 1.10 = 11.00), so no amount check flags the merge.
Keep supplier item code, buyer item code and invoice number in separate columns. If your team wants a normalized matching code, build it beside the untouched supplier value and document the rule. A successful lookup does not authorize overwriting the original reference.
How do you test that codes survive a CSV round trip?
Run a small synthetic test set before a large batch, then repeat it after saving and reopening through the receiver’s actual import path. Expected values are exact text, punctuation included.
| Source reference | Why it belongs in the test | Acceptance condition |
|---|---|---|
000742 / 0000742 | Different zero counts | Two different strings remain |
12345678901234567 | 17 digits, above 15-digit number precision | All 17 original digits survive as text |
1E10 | Looks like scientific notation | Literal 1E10, not a calculated number |
03-04 | Looks like a date | Literal code, not a date value |
A-0742 | Punctuation matters in matching | Hyphen and zero remain |
A length check flags a loss, but cannot prove identity: “000743” also has six characters. To see what the CSV really contains, open the saved file in a plain text editor rather than in the spreadsheet. If one reference changes at any stage, stop product matching and reimport from the original.
Can you get leading zeros back after Excel removed them?
Not reliably from the sheet alone. A display format can make the stored 742 look like “000742”, but it cannot tell you whether the source said “742”, “000742” or “0000742”. Recover the original string from the PDF or an authoritative supplier file, then repeat the import with the code column as text.
Padding with TEXT() or a custom format is defensible only when a verified supplier specification fixes the width. For long references the damage is final: converting an already rounded 17-digit number to text preserves the rounded value, not the missing digits.
If every code survives but a lookup still fails, look at case, spaces and punctuation under the receiving system’s matching rules. Create an explicit matching key beside the source reference; do not trim or change case in the original column, because different suppliers use different code systems.
FAQ
Why does Excel remove leading zeros from my CSV?
Because opening the CSV directly lets Excel guess column types, and a code made of digits is guessed as a number. Import the file and set the code column to Text instead.
Does a custom number format keep leading zeros?
It only displays them. The stored value is still the number, so formulas and lookups see 742, not 000742, and the displayed zeros may not match the source.
How do I keep leading zeros when I save as CSV?
Store the codes as text, save, then check the saved file in a text editor. Whoever opens it next must also import the column as text, because CSV carries no column type.
Should I pad all item codes to the same length?
Only when the supplier’s specification defines that length. Otherwise padding invents characters and can merge or split products.
Continue the checks
Amounts have a similar trap: see how Excel reads decimal separators in invoice amounts. Before importing, check whether the invoice is a scanned or text-based PDF, and keep line items separate from header fields.
InvoiceLineLab turns supplier invoice lines into reviewable spreadsheet rows. The synthetic invoice example shows identifiers kept as text, invoice data validation line by line lists the checks, and the monthly plan billed per PDF page sets the price.