Keep leading zeros when converting CSV to Excel
Treat product codes and postal codes as text, before a spreadsheet changes them.
Quick answer. Use the original CSV and import identifier columns as Text, or create a text-only XLSX. Formatting a number after conversion cannot recover discarded digits. CSV itself cannot store column types.
Try a file with a known result
Original synthetic teaching data; no customer records. Download the small sample, then load it into the matching tool. Your own files remain in your browser.
Settings for this example
Load the sample in CSV to Excel. Choose Comma, keep First record is a header on, and preview before downloading XLSX.
Expected results to compare
- The preview contains 2 data records and 4 columns; the header is separate.
- The first row shows 00127, 02108 and the complete 12345678901234567 reference.
- With default settings every XLSX field, including quantity 12, is text. Compare both identifiers and the last row. For calculations, explicitly choose Number for quantity before exporting; keep the identifier columns as Text.
- Number on product_id lists source records 2 and 3 with “Leading zeros would be lost” and blocks download. Number on quantity alone reports 2 numeric cells and allows download. Reset identifier columns to Text before you download.
This sample demonstrates preservation from an intact source. It does not demonstrate recovery of a CSV that already contains 127 or a rounded reference.
Open the matching tool →Start with the original export
Consider this teaching example: a product code is 00127, a postal code is 02108, and a reference is 12345678901234567. They identify records; they are not quantities to add together.
product_id,postal_code,reference,quantity 00127,02108,12345678901234567,12 00904,00501,98765432109876543,3
Download the same teaching bytes from /samples/leading-zeros.csv, or load “Leading zeros” from the tool sample pack. A CSV holds characters and separators, not spreadsheet column types. When a spreadsheet interprets a field as a number, its displayed value can change. Microsoft documents both leading-zero removal and Excel’s fifteen-significant-digit numeric precision limit. Saving identifiers as text avoids that numeric conversion.
Before and after: Excel mess versus text workbook
A casual general-format open often shows:
product_id postal_code reference quantity 127 2108 1.23457E+16 12 904 501 9.87654E+16 3
Zeros disappear; the long reference becomes an exponent. A text-preserving XLSX from CSV to Excel keeps the source characters:
product_id postal_code reference quantity 00127 02108 12345678901234567 12 00904 00501 98765432109876543 3
Compare the formula bar, not only a padded display format. Display zeros without restoring the underlying value are still a failed handoff.
Convert without guessing the column types
- Open the CSV to Excel converter and load the original file, the sample pack entry, or the downloadable sample.
- Preview it. Confirm that the product code still begins with two zeros and the long reference matches digit for digit.
- Download the XLSX workbook. Every column defaults to Text, including dates and formula-like fields. Keep identifier columns as Text. Optionally select Number for quantities in Excel column types before downloading.
- Open the workbook and compare a few records with your export. Check that chosen quantity columns are numeric if you need sums or numeric sorting.
Open the text-preserving converter →
Step-by-step troubleshooting
- Preview already shows 127. The CSV lost zeros earlier. Re-export from the source system — see Repair versus re-export.
- Reference looks like 1.23E+16 in the CSV. Digits are gone; local tools cannot expand the exponent. Use a fresh export and keep the column on Text (scientific notation).
- Whole file is one column. Fix the delimiter with CSV check & repair first (one-column guide).
- Only some rows lost zeros. Mixed columns still need Text for the identifier column; Number is only for true quantities.
Two checks that catch a misleading result
First, inspect the value itself rather than only its appearance. A custom display format can show a fixed number of digits without changing the underlying value. Second, compare a long reference from beginning to end. A familiar-looking start does not prove its later digits were retained.
TableMender keeps all fields as text by default in its XLSX output; explicit number-column choices change that behavior. It does not restore zeros or digits that were already removed in an earlier export.
If you import directly in Excel
Microsoft provides an alternative: use the text/CSV import workflow and set identifier columns to Text before loading them. Interface names differ by Excel version. Consult Microsoft’s instructions for your installation, and use the original file rather than a workbook that has already converted the identifiers.
Honest limits
Already-truncated codes such as 127 cannot gain zeros from formatting or from this converter. The tool does not pad to a guessed width, dial postal authorities or validate check digits. Leading zeros, more than 15 significant digits, spaces and ambiguous number notation block numeric export for that cell. Blank numeric fields stay blank; a two-decimal format changes appearance without rounding the stored value. Size failures at 5 MiB or 20,000 records are capacity limits, not evidence that zeros are safe as numbers.
When a text-only workbook is the wrong tradeoff
If you need quantities, dates or formulas to behave as typed spreadsheet values, this first version does not infer them. Keeping a code intact takes priority over automatic conversion. For a mixed workbook, keep a source copy and choose Number only for appropriate columns.
Edge cases and boundary cases
Postal codes that look like octal or that begin with zero in one country and not another still need Text. Excel Save As CSV after a General-format open is a common way zeros disappear permanently — read Excel Save As CSV pitfalls before overwriting the original download. Very long identifier fields still must stay under 32,767 characters.
Related Excel import problems
Leading zeros are one rewriting injury. Excel can also turn ship windows and short codes into dates, or shorten long tracking IDs into scientific notation. Read Stop Excel from turning text into dates when a range or letter-number token changes, and Large CSV numbers and scientific notation when a long reference becomes an exponent. Scene guides cover SKUs, phone numbers and ZIP+4. Matching tools: CSV to Excel and CSV check & repair.
Number export on leading-zeros.csv
Load leading-zeros.csv in CSV to Excel with Comma and a header. Preview shows 2 data records and 4 columns. Leave every column on Text and download. Then try one Number column at a time. The header is source record 1, so the first data row is source record 2. The on-page list names the source record and the column header. Download stays blocked while any issue remains. Reset the column to Text before you download.
| Column set to Number | What the converter reports |
|---|---|
| product_id | Source records 2 and 3, column 1: Leading zeros would be lost. 00127 and 00904. 0 numeric cells. 2 values need attention. |
| postal_code | Source records 2 and 3, column 2: the same leading-zero message. 02108 and 00501. |
| reference | Source records 2 and 3, column 3: More than 15 significant digits. Both values are 17 digits and do not start with zero, so this is the precision guard. |
| quantity | Accepted. 2 numeric cells (12 and 3), 0 blank, download allowed. Two-decimal display is also accepted and does not rewrite those stored values. |
Record 3 fails product_id the same way record 2 does. A custom ZIP or product-code format in Excel can print a zero on screen and still store 2108 or 127. Compare the formula bar with the CSV.
What preflight says on this file
After Preview, the identifier row warns: leading zeros in columns 1 and 2 (4 cells) and 16+ digit tokens in column 3 (2 cells). The how-to link on that row opens long digit IDs. Link order is scientific notation, then 16+ digit tokens, then ZIP+4, then plus-prefixed phones, then leading zeros. This sample’s 17-digit reference wins the link. The warning text still names the leading zeros. Read both guides when one file has padding and a long reference.
The formula-like row stays clear. 00127 does not begin with =, +, @ or -. There is no fully blank data record and no exact whole-row duplicate. A clear duplicate row leaves the codes as text.
FAQ grounded in CSV to Excel
Can the tool pad 127 back to 00127? No. It does not guess a width. If the preview already shows 127, re-export. See Repair versus re-export.
Why do product_id and reference fail with different sentences? 00127 matches the leading-zero guard. 12345678901234567 matches the 15-significant-digit guard. Both columns stay Text. The long-token case is written up in scientific notation and long digit IDs.
Should quantity stay Text? Text is the default and is safe. Choose Number only when you need a sum. Identifier columns stay Text either way. The -converted workbook does not replace the CSV.
Sources:
Examples are original teaching data. Tool-specific behavior describes this version of TableMender; software interfaces can vary by version.