Skip to content
migration.tools

data · csv · excel

Why your CSV import failed: encodings, delimiters and lost leading zeros

Why CSV imports break — mojibake, BOMs, semicolon delimiters, Excel dropping leading zeros, line breaks inside values — and how to fix each before you upload.

By

Updated · first published · 5 min read

A spreadsheet grid with problem cells highlighted: a ZIP code losing its leading zero, garbled accented characters, and a semicolon where a comma was expected.

Key points

  • CSV has no single standard. RFC 4180 describes the common format, but delimiters, quoting, encodings and line endings all vary between programs.
  • Text like 'Café' means UTF-8 bytes were read as Windows-1252. Re-read the file as UTF-8; don't fix the characters by hand.
  • Opening a CSV in Excel and saving it again can silently change data: leading zeros disappear, numbers over 15 digits lose precision, and some values become dates.
  • Excel in many European locales writes semicolon-separated 'CSV', because the comma is the decimal separator.
  • A byte order mark (BOM) helps Excel detect UTF-8 but can turn the first header into an unrecognised column name in other importers.

CSV looks like the simplest data format there is: values, separated by commas, one record per line. That simplicity is the problem. There is no authority that enforces what a CSV file must contain, so every program that writes one makes its own choices — and every program that reads one has to guess which choices were made.

When an import fails, or worse, succeeds with damaged data, the cause is nearly always one of the problems below.

The "standard" that isn't

RFC 4180 is the closest thing CSV has to a specification. It documents the common conventions: fields separated by commas, records separated by CRLF line breaks, fields containing commas, quotes or line breaks wrapped in double quotes, and a double quote inside a field written as two double quotes ("").

It describes what many programs do; it doesn't require anything of them. In practice you will meet files with semicolons or tabs as delimiters, LF or CR line endings, single quotes, backslash escapes, and no quoting at all. A robust importer — or a cleaning step before it — has to handle all of them.

Encoding: when "é" becomes "é"

Text in a file is stored as bytes, and the encoding is the rule for turning bytes back into characters. CSV files don't say which encoding they use, so the reader guesses.

The classic symptom is mojibake: Café shows up as Café, and Müller as Müller. That particular pattern has one cause: the file is UTF-8, but it was read as Windows-1252 (or Latin-1). In UTF-8, é is two bytes; read as Windows-1252, each byte becomes its own character.

The opposite also happens. Excel on Windows has long saved plain "CSV" in the system's legacy code page, typically Windows-1252 in Western Europe and the Americas. An importer expecting UTF-8 then either rejects the file or replaces accented characters with �.

The fix is never to correct characters by hand. Decode the file with the right encoding and re-save it as UTF-8. The convert to UTF-8 tool detects UTF-8 and UTF-16 reliably, falls back to Windows-1252 for legacy exports, and lets you pick the source encoding yourself when the preview still looks wrong.

The byte order mark

A UTF-8 file may start with three invisible bytes, EF BB BF, called a byte order mark (BOM). Excel uses it to recognise UTF-8 when opening a CSV — without it, Excel may misread accented characters.

Other software doesn't expect it. To an importer that doesn't strip the BOM, your first column isn't called id; it's called id, which looks identical on screen and matches nothing. If an import complains that a column you can plainly see doesn't exist, and it's the first column, suspect a BOM.

The rule of thumb: include a BOM for files people will open in Excel, and leave it out for files that machines will import.

Delimiters: the semicolon problem

In much of Europe and South America the comma is the decimal separator: one and a half is written 1,5. Excel follows the operating system's regional settings, so in those locales it saves "CSV" files separated by semicolons. A file from a colleague in Berlin or Paris may look like this:

id;name;price
1;Widget;12,50

An importer expecting commas sees a single column called id;name;price. Detect the delimiter from the header row, and check whether decimal commas need converting before the numbers are parsed.

What Excel does to your data

Opening a CSV in Excel is not a neutral act. Excel interprets every cell, and if you save the file again, its interpretation replaces your data:

  • Leading zeros disappear. ZIP codes, phone numbers and product codes such as 00501 become 501.
  • Long numbers lose precision. Excel keeps 15 significant digits, so a 16-digit card number or an 18-digit order ID has its final digits replaced with zeros, and is displayed as something like 1.23457E+17.
  • Values become dates. 3-4, 1/2 and MARCH1 can all turn into dates. This was common enough that in 2020 the HUGO Gene Nomenclature Committee renamed several human genes, such as SEPT1 and MARCH1, partly to stop spreadsheets from converting them.

If a file has been through Excel, check identifier columns before importing it. If you're producing data for someone who will open it in Excel, consider sending a real .xlsx where text columns are stored as text. And when you need to get data out of a workbook, the Excel to CSV converter writes formulas as their values and dates in ISO format, without opening Excel at all.

Line breaks inside values

A quoted field may legally contain a line break — an address, a product description, a comment. That means one record can span several lines of the file.

Tools that process CSV line by line get this wrong. wc -l overcounts records; a script that splits a large file every 10,000 lines can cut a record in half; a quick grep returns fragments. Use a CSV-aware parser for anything that counts, splits or filters rows. The CSV splitter splits on record boundaries and repeats the header in each part, which is what most upload limits need.

Line endings themselves vary too: Windows writes CRLF, macOS and Linux write LF. Most importers accept either, but strict ones don't, and mixed endings in one file confuse almost everything. The line ending converter normalises them.

The quiet ones: whitespace, duplicates and empty rows

Some problems don't stop an import; they corrupt it:

  • Trailing spaces make "Paris " and "Paris" two different cities.
  • Non-breaking spaces (U+00A0), common in data copied from web pages, look like spaces but aren't matched by most trimming functions.
  • Duplicate rows create duplicate customers.
  • Empty rows at the end of an export become blank records.
  • Duplicate header names make one column silently overwrite another when rows are turned into objects.

The CSV cleaner handles most of these in one pass: it trims and collapses whitespace, drops empty rows, removes duplicates by whole row or by a key column such as email, can blank out placeholders like NULL and N/A, and normalises headers — then reports how many of each it changed.

Dates: 03/04/2026 is two different days

In the United States, 03/04/2026 is March 4th. Almost everywhere else, it's April 3rd. Nothing in the file says which was meant, and both are valid dates, so nothing fails — the data is simply wrong for some rows.

Wherever you control the export, use ISO 8601 dates (2026-04-03). Where you don't, check a value with a day above 12 to work out the convention before importing.

A pre-import checklist

  1. Encoding: convert to UTF-8; strip the BOM unless the file is for Excel.
  2. Delimiter: confirm it from the header; check for decimal commas.
  3. Identifiers: check that leading zeros and long numbers survived.
  4. Structure: count records with a CSV parser, not by lines.
  5. Clean: trim whitespace, remove empty and duplicate rows.
  6. Map: rename and reorder columns to the target's template with the CSV column mapper.
  7. Split to the target's upload limit if needed.
  8. Convert if the target wants another format — the CSV to JSON converter keeps ZIP codes and IDs as strings instead of guessing they are numbers.

Each step takes seconds. Skipping one is how a clean-looking import ends up with 2,000 customers named Café.

About the author

Abdessamad Bettal, full-stack engineer and the developer of migration.tools — free, private, browser-based tools for moving databases, data, websites and content between systems.

LinkedIn GitHub