# A CSV Opens as Garbled Text: Check the Encoding Before You Re-Import

Authored ToolFlowKit practice material. These records are teaching examples, not customer data, current vendor offers, or measured software results.

## Which of the three failures are you looking at?

The visible damage shows where the loss happened. Compare a value you can spell, such as a city or a surname, rather than a random row that happens to look wrong.

The first, third and fourth rows ask the same question three ways: was the damage done by a reader's wrong assumption, by a mark left in the file, or by a lossy conversion that ran and then ran again. Only the second and fourth rows are permanent.

| What the cell shows | What the bytes were | What happened | Can a conversion recover it? |
| --- | --- | --- | --- |
| CafÃ© | 43 61 66 C3 A9 | UTF-8 text was decoded as Windows-1252 or Latin-1. The characters are intact; the reader made the wrong assumption. | Yes, once. Decode as UTF-8 and write with the target encoding. |
| Łódź written as L?d? or 東京 as ?? | A legacy codepage with no mapping for those characters | The export converted from Unicode into Windows-1252 or a similar codepage and substituted the unmapped characters. Characters that codepage does contain, such as é at E9, survive this step. | No. The substituted characters are gone; export again from the source system with UTF-8. |
| ï»¿Date in the first header | EF BB BF, then the header bytes | A UTF-8 byte-order mark survived into the field name because the reader did not strip it. | Yes. Strip the prefix, or read with utf-8-sig. |
| 锟斤拷 or a run of question marks | Replacement bytes, decoded again | A conversion already failed and wrote replacement bytes. A later reader decoded those bytes under a different codepage, which turned them into new characters. The pattern varies with the second codepage, so the visible result is not stable. | No. Go back to the export that came before the first failed conversion. |

## When does a UTF-8 byte-order mark help, and when does it break a field name?

The mark is the three bytes EF BB BF at the start of the file. In UTF-8 it is not a byte-order signal at all: the Unicode FAQ describes it as an encoding signature that distinguishes UTF-8 from other encodings, with nothing to do with byte order.

It helps when the reader is a desktop spreadsheet that would otherwise guess the encoding from the system locale. It hurts when the reader passes those bytes straight into the first field, so the header arrives as ï»¿Date and every later reference to that column name fails.

Desktop suites let you choose the encoding on both sides of the trip. LibreOffice's CSV filter takes a character-set token on import and export, which is why the same file can open correctly once the filter is told what to expect and wrongly when it is left on the system default.

| Reader | What the mark does | Practical choice |
| --- | --- | --- |
| Desktop spreadsheet opened by double-click | Often the only signal that the file is UTF-8 rather than the local legacy codepage | Write with the mark when the file is meant for that reader |
| Script or import process you control | Becomes three characters in the first field unless the reader strips them | Read as utf-8-sig, or strip EF BB BF before parsing |
| Two systems exchanging files on a schedule | Adds one difference that has to be handled on one side | Agree once and record the choice with the export contract |

Guide: https://toolflowkit.com/guides/csv-encoding-repair

License: CC0 1.0.
