Browser-based encoding repair · the file is decoded here, never sent

Fix CSV Encoding

Find out what encoding a CSV or text file really uses, fix accents that show as é or ü, and save it as UTF-8 (with or without BOM) or UTF-16LE for Excel. You can override the guess and see the result before downloading.

File

Drop a CSV or text file

Any encoding, up to 50 MB

Fix CSV Encoding and Garbled Accents for Excel

Operator: Abdulla Al Fahad. How tools are built and checked

There are two different reasons a CSV shows José as Jos? or José, and they need opposite fixes. Either the file is in an old code page and the program read it as something else, or the file is already UTF-8 but was read as Windows-1252 and saved again, so the damage is in the text itself. This page tells the two apart and fixes both.

Drop the file and it reports what it found and why: a byte-order mark, valid UTF-8, or the legacy encoding that gives the most plausible text, with the runners-up and their scores. You can overrule the choice, see the first lines as they will be saved, and download UTF-8, UTF-8 with a BOM, or UTF-16LE.

Key features

  • Detects byte-order marks, UTF-16 without a mark, valid UTF-8 and 23 legacy encodings from Windows-1252 and Shift_JIS to GBK, Big5 and EUC-KR
  • Scores candidates on the first 256 KB and shows each score with its evidence
  • Repairs garbled UTF-8 such as é, ü and ’, once, twice or automatically (Automatic acts only when at least 3 sequences look garbled)
  • Saves as UTF-8, UTF-8 with BOM or UTF-16LE, with optional LF or CRLF line endings
  • Also reads .txt, .tsv and any other text file of up to 50 MB

How the encoding is worked out

A BOM decides immediately: EF BB BF is UTF-8, FF FE is UTF-16LE and FE FF is UTF-16BE. A UTF-32 mark is reported but cannot be read, because browsers have no UTF-32 decoder. With no BOM, a file in which every second byte is zero is taken as UTF-16. A file with many zero bytes that is not UTF-16, or one made of only one or two distinct byte values (256 identical bytes, say), is refused as binary. Otherwise the bytes are tested as strict UTF-8. Valid UTF-8 with at least one non-ASCII character is reported as UTF-8, because legacy text almost never happens to form valid multi-byte sequences. Only when UTF-8 fails is each legacy decoder tried; one whose bytes are invalid in that encoding (as for most Shift_JIS or GBK guesses on Western text) is dropped.

The browser's decoders follow the WHATWG Encoding Standard, which maps the label ISO-8859-1 to Windows-1252 and ISO-8859-9 to Windows-1254. The page therefore lists those as Windows-1252 and Windows-1254. The two differ from the ISO versions only in the 0x80-0x9F range, where Windows adds printable characters such as the euro sign and curly quotes.

How it works

Each surviving candidate decodes the sample and is scored on its non-ASCII characters: the share that are letters, minus penalties for control characters, replacement characters, stray symbols and, for cased scripts, an implausible share of capitals. The scores are multiplied by how uniform the script is, so Cyrillic mixed with random Latin accents loses.

Two byte-level checks do most of the work. Western text puts accented letters between ASCII letters, so high bytes sit alone; Cyrillic, Greek, Hebrew or Arabic text puts them in runs, so a Latin reading of a run-heavy file is penalised. For East Asian encodings, kana (Japanese), common simplified or traditional characters (GBK and Big5) and Hangul decide between the multi-byte candidates.

Common use cases

  • A finance analyst receives an ERP export of 18,000 rows where München is M�nchen. The page counts the replacement characters already baked into the text and warns that no encoding or repair can bring the umlauts back, so she asks for a fresh export instead of trusting a guess.
  • A marketing team opens a Windows-1251 mailing list that Excel shows as Ïðèâåò. The file's high bytes come in long runs, so the Cyrillic candidates outscore every Latin one and the preview reads Привет.
  • A developer has a customer file whose notes column was converted twice. ’ needs three sequences in round one and one in round two to become an apostrophe.
  • A shop owner needs a comma-separated product file with Japanese names to open in Excel by double-click, and saves it as UTF-8 with BOM.

How to use this tool

  1. Drop the file; the encoding, confidence and reason appear at once.
  2. If the preview looks wrong, pick another candidate from the table or from Read the file as.
  3. Leave Repair garbled accents on Automatic unless you know the file is clean.
  4. Choose the output encoding and line endings, check the preview, and download.
  5. Open the result in Excel through Data > From Text/CSV if accents still look wrong there.

Example

A UTF-8 file that was read as Windows-1252 and saved again

Zoë Ångström;Malmö

After repair

Zoë Ångström;Malmö
(4 garbled sequences repaired in 1 round)

Tips for best results

  • Excel assumes the system code page for a UTF-8 CSV without a BOM, so choose UTF-8 with BOM when the file will be double-clicked; most import tools and databases prefer UTF-8 without it.
  • A confidence of medium or low on a short Western file is normal: é, ü and ç decode the same in Windows-1250, 1252 and 1254, so only the odd letter such as Å or ø separates them.
  • Use UTF-16LE only for tab-separated files going into Excel; a comma-separated UTF-16 file can open in a single column.

Common pitfalls

A byte that is invalid in the chosen encoding becomes the replacement character and the original is gone. Repair works on garbled text, but it cannot restore characters that were already replaced by question marks or �.

Repair rewrites only sequences that decode to exactly one ordinary letter, symbol or punctuation mark, and Automatic needs at least 3 of them. That keeps correct text such as Gruß… (a sharp s followed by an ellipsis, which would otherwise decode to an N'Ko letter) untouched, but a file with only one or two real garbled sequences is left as it is until you choose one round. The first twelve before-and-after pairs are shown so you can spot a wrong rewrite.

The detection is statistical. Short files, or files in several encodings pasted together, can fool it; the candidate table exists so you can choose.

The output is a transcoding of the text, not a re-export from the source system, so quote characters, delimiters and line breaks inside fields are left as they were.

Common errors and how to fix them

"12 bytes cannot be decoded as ... and become the replacement character"
Some bytes are not valid in the selected encoding. Pick another candidate, or if the file mixes encodings, split it and convert each part.
"The file holds many zero bytes and is not UTF-16, so it looks like a binary file rather than text."
It is probably a spreadsheet (.xlsx, .xls), a database dump or an archive saved with a .csv name. Export it as CSV from the program that made it.
"The file uses only one byte value, repeated ... so it is treated as a binary or filler file."
A file of one or two distinct byte values is padding or a placeholder, not text. Check that the export did not write blanks instead of data.
"A UTF-32 byte-order mark is present. Browsers have no UTF-32 decoder"
Convert the file to UTF-8 or UTF-16 first, for example with iconv -f UTF-32 -t UTF-8, then open it here.

Best practices

  • If you control the producer, write UTF-8 and state it, rather than relying on detection: a BOM plus a documented encoding removes the whole class of problem this page repairs.

Frequently asked questions

Why does it say UTF-8 for a file that only contains plain English?

A file with only ASCII bytes is identical in UTF-8, Windows-1252 and every other encoding listed, so it reports ASCII (valid UTF-8). Choosing a BOM output is the only change the conversion makes.

How is mojibake different from a wrong encoding?

In a wrong-encoding file the bytes are right and only the reading is wrong, so choosing the correct encoding fixes it. In mojibake the text itself already contains the garbled characters, so the file reads cleanly as UTF-8 and the repair step rewrites the text.

Does converting change the data in my cells?

Only the bytes change. No cell is parsed, trimmed or reformatted, and formulas and quoting stay as written, so a cell that begins with = or + is saved exactly as it arrived.