I spent a week chasing two bugs that both came from the same place: an eBay order report opened in Excel before it ever reached my code.
Neither bug was exotic. One was a header that was not on row 1. The other was a 22-digit tracking number that quietly became 9.4E+21. Both survive a quick eyeball check, and both corrupt a packing batch in ways you only notice after printing.
Here is what the export actually did, and the two small guards I now keep in the parser.
Bug 1: the header is not always the first row
A CSV export is a text file, but the thing that produces it often writes a title block first:
Order Report,,,,, Date range: 2026-11-01 to 2026-11-30,,,,, Order number,Buyer username,Item title,Quantity,Tracking number 12-11847-22910,demo_buyer_01,Enamel Mug 11oz,2,9400111200000000000000 If your parser does header = rows[0], every column name becomes Order Report or an empty string, the mapping UI shows nothing usable, and the whole batch fails validation for a reason that has nothing to do with the seller's data.
The fix is to stop assuming and start scoring. Look at the first 10 rows, count how many of them look like plausible headers, and take the best one:
const KNOWN = [ 'order number', 'order id', 'buyer username', 'item title', 'quantity', 'tracking number', 'custom label', 'sku', 'price' ]; function findHeaderRow(rows, maxScan = 10) { let best = { index: 0, score: -1 }; rows.slice(0, maxScan).forEach((row, index) => { const cells = row.map((c) => String(c || '').trim().toLowerCase()); if (cells.length < 2) return; const hits = cells.filter((c) => KNOWN.some((k) => c === k || c.includes(k))).length; // 空列太多的行不可能是表头 const filled = cells.filter(Boolean).length; const score = hits * 2 + (filled / cells.length); if (hits >= 2 && score > best.score) best = { index, score }; }); return best.index; } Two details matter more than the scoring formula:
- Require at least two known column names. A title row can contain the word "order" and still be junk.
- Keep the detected index visible in the UI ("header found on row 3"). When a seller sends you a file where the header is on row 7, you want that on screen, not buried in a log.
Once the header row is right, the rest of the mapping is ordinary work: order number to Order ID, Custom Label to SKU, quantity to quantity. Multi-row orders merge by order number, and a buyer with two different order numbers stays two shipments. That part is boring, which is the point.
Bug 2: Excel eats long tracking numbers
USPS tracking numbers are 20 to 22 digits. Excel stores numbers as IEEE 754 doubles, which hold about 15 to 16 significant digits. Open a CSV by double-clicking it and the last digits are gone before you see them:
9400 1112 0000 0000 0000 00 -> 9.40011E+21 Worse, it is not a display setting you can undo by widening the column. The value is already rounded. Copy it back out and you get 9400111200000000000000 only if you are lucky with the rounding; usually you get a trail of zeros that no longer matches any shipment.
There are two separate defenses, and you need both.
Defense one: never let the value become a number. In the browser, read the file with FileReader as text and split it yourself. Do not run a tracking column through Number(), parseFloat(), or any schema library that infers types. Everything from a CSV is a string until you decide otherwise.
Defense two: validate the string you got. A tracking number that arrived as 9.40011E+21 is not recoverable, but it is detectable, and detection is what saves the batch:
const SCI = /^\d(\.\d+)?e\+\d+$/i; function checkTracking(raw) { const value = String(raw || '').replace(/\s+/g, ''); if (!value) return { ok: false, reason: 'missing' }; if (SCI.test(value)) return { ok: false, reason: 'lost to scientific notation' }; if (!/^\d+$/.test(value)) return { ok: false, reason: 'non-digit characters' }; if (value.length !== 20 && value.length !== 22) { return { ok: false, reason: `unexpected length ${value.length}` }; } return { ok: true, value }; } The length check is not cosmetic. A 21-digit string is almost always a 22-digit number with a dropped digit, and dropping a digit is the single most common paste error I see in seller files. Flagging it before printing beats discovering it at the post office.
One more case worth handling: SKUs and order numbers with leading zeros. 00123 becomes 123 the moment a spreadsheet touches it. Same rule applies, keep them as strings, and if you must round-trip through a spreadsheet, import that column as Text.
What I changed in the actual workflow
- The parser sniffs the header row and shows which row it picked.
- Every column stays a string until the mapping step explicitly converts quantity to an integer.
- Tracking numbers are validated for scientific notation, digit-only content, and 20/22 length before the batch is allowed to print.
- The print step never reads the tracking column for layout. A bad tracking number should block a warning, not silently resize a 4x6 label.
None of this is clever. It is the difference between a batch that prints six correct packing slips and a batch that prints six slips with the same rounded tracking number on all of them.
Try the two failing cases
If you want to see the checks against real UI instead of a snippet, I put the format reference and a validator here: https://orderquill.com/usps-tracking-number-format
It covers the common USPS prefixes (9400, 9205, 9200, 9405, 9202), expected lengths, and what a service-code mismatch usually means. The same CSV-to-packing-slip flow lives at https://orderquill.com/packing-slip-generator, free for up to 20 orders per batch, no signup.
For the fee side of the same batch, there is a separate calculator that takes the same order CSV: https://orderquill.com/ebay-fee-calculator
Sample files used in this post, including one with a title row and one with a destroyed tracking column, are in the open repo: https://github.com/yhx123/ecommerce-order-csv-samples
All order data in the screenshots is fictional. The tool does not buy postage and does not generate carrier labels.
![Legged Robot Mechanics and Dynamics — Ch.07: Energy Management [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0orytkfqpv0aqm7xevhr.png)
![Legged Robot Mechanics and Dynamics — Ch.08: Mechanical Design [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyj7esd590kzopbgd8m10.png)

