How to fix mojibake in a CSV or Excel file
You open a file and see ¶©µ¥ºÅ, café, 丠or 锟斤拷.
In most cases no data is lost — the bytes are intact and the decoder was wrong. Here is how to tell which case you have.
Which mojibake is it?
| What you see | What happened | Recoverable? |
|---|---|---|
¶©µ¥ºÅ, ÕÅÈý (Latin-1 symbols and accented letters in odd places) | A GBK/GB18030 file read as cp1252/windows-1252 | Yes — reverse the bytes |
café, 丠| UTF-8 read as latin-1/cp1252 | Yes — very common in web exports |
锟斤拷 | UTF-8 bytes read as GBK, with replacement characters (U+FFFD) already substituted | No — the original bytes are gone |
Everything becomes ? | A lossy conversion happened | No |
The first two are lossless: each character maps back to exactly one byte. The last two are lossy, and the difference decides whether a repair is even possible.
Fix it in Python
# A GBK file that was opened as cp1252
text = open("garbled.csv", encoding="cp1252", errors="strict").read()
fixed = text.encode("cp1252").decode("gb18030")
open("fixed.csv", "w", encoding="utf-8-sig", newline="").write(fixed)
utf-8-sig writes a BOM so Excel opens the result correctly on double-click.
Why "it decoded without an error" proves nothing
Two facts people trip over:
latin-1can decode every byte sequence — it never raises. A successful decode is not evidence the encoding was right.b"A\x00B\x00"is valid UTF-8 (it decodes toA\0B\0), so a UTF-16LE file can pass a UTF-8 check. Order matters: check BOM/NUL before trying UTF-8.
So a repair should be gated on structure, not on "it didn't throw". In my tool a CJK repair only applies when the input has
no CJK, at least 25% high single-byte characters, at least one byte in the 0xA1–0xBF band, and the result is at
least 20% CJK. Otherwise the answer is uncertain — a wrong "fix" corrupts a file that was probably fine.
Do it without code
Paste the garbled text and watch it come back:
In-browser repair tool — runs locally, nothing uploaded →
Or I can do the whole file (CSV, or cells inside .xlsx): $10 per file, 12 hours, paid in USDC. Prices and how to order.
Looking for what ’ or é mean? Computed table, with the cases that cannot be undone.