Excel leading zeros in invoice item codes

Excel drops leading zeros when it reads a code as a number. Import item codes as text, test 000742 and 17-digit references, and verify the CSV round trip.

See the PDF-to-Excel example

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 12345678901234567 typically 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 1E10 can be read as 10,000,000,000.
  • Date-looking codes. A code such as 03-04 can 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.

SituationMethodKeeps the original characters?
Typing or pasting codesFormat the column as Text before entering values, or type an apostrophe first ('000742)Yes
Importing a CSV or text fileUse 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 editorSet the column type to Text before any automatic type-detection step converts itYes, if no earlier step changed it
Codes already stored as numbers, known fixed width=TEXT(A2,"000000") in a new columnOnly if the width is verified for that supplier
Display onlyCustom number format 000000No: the stored value is still 742

Steps for a supplier CSV:

  1. Keep an untouched copy of the file.
  2. Open a blank workbook and start the text/CSV import rather than double-clicking the file.
  3. Select the delimiter, then mark every identifier column (item code, supplier reference, PO number, invoice number) as Text.
  4. Leave quantities and amounts numeric; they need their own checks.
  5. 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:

LineItem code on the PDFQuantityUnit priceLine net
1000742412.5050.00
2000074228.0016.00
3742101.1011.00
Total77.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 referenceWhy it belongs in the testAcceptance condition
000742 / 0000742Different zero countsTwo different strings remain
1234567890123456717 digits, above 15-digit number precisionAll 17 original digits survive as text
1E10Looks like scientific notationLiteral 1E10, not a calculated number
03-04Looks like a dateLiteral code, not a date value
A-0742Punctuation matters in matchingHyphen 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.

Sources and further reading

Get started with InvoiceLineLab

Enter your work email to get access to InvoiceLineLab. No account or payment is created at this stage.

Submitting sends your email and visit context to our publisher’s infrastructure, named on the Privacy page. No account, payment or automatic email is triggered. Privacy.