実例: Excel が吐いた Shift_JIS の CSV を、証拠つきで直す
下の 4 つは、このページを生成するときに実際にファイルを処理して得た結果です。手で書いた見本ではありません。
1. 届いた状態(同じバイト列を UTF-8 として読んだ場合)
| 1 | ���i�R�[�h,���i��,�P��,����,�S�� |
| 2 | A-1001,��i�X�Y�j,120,30,�c�� |
| 3 | A-1002,�݂���i���Q�Y�j,80,45,���� |
| 4 | B-2001,�� 500ml,150,12,��� |
| 5 | B-2002,�ق����� 500ml,150,8,��� |
| 6 | C-3001,�̂�ٓ�,450,20,���� |
Windows-1252 として読むと、こう見えます:
| 1 | �¤•iƒR�[ƒh,�¤•i–¼,’P‰¿,�”—Ê,’S“– |
| 2 | A-1001,‚è‚ñ‚²�i�Â�XŽY�j,120,30,“c’† |
| 3 | A-1002,‚Ý‚©‚ñ�iˆ¤•QŽY�j,80,45,�²“¡ |
| 4 | B-2001,—Î’ƒ 500ml,150,12,—é–Ø |
| 5 | B-2002,‚Ù‚¤‚¶’ƒ 500ml,150,8,—é–Ø |
| 6 | C-3001,‚Ì‚è•Ù“–,450,20,�‚‹´ |
2. 修復後
| 1 | 商品コード,商品名,単価,数量,担当 A-1001,りんご(青森産),120,30,田中 A-1002,みかん(愛媛産),80,45,佐藤 B-2001,緑茶 500ml,150,12,鈴木 B-2002,ほうじ茶 500ml,150,8,鈴木 C-3001,のり弁当,450,20,高橋 |
3. 一緒に渡すレポート
# Encoding repair report - file: `sales_sjis.csv` (201 bytes) - sha256 (input): `8d305b6203e018338d7277d5e4b61d0106f7e3c7cf57b983196a189f9352c197` - result: `sales.utf8.csv` - sha256 (output): `670d5b5dd7499f5e13138b05d8d48d6c741588f002bd06e54003e622daac64cd` - encoding identified: **cp932** (score 114.1) - U+FFFD present: no - ambiguous: no ## How the encoding was chosen Candidates are scored, not guessed: U+FFFD (lost bytes), private-use characters (invented characters), words that mix Latin and CJK, halfwidth katakana, and the share of common CJK characters all move the score. Full rules: `mojibake_repair/core.py`. | encoding | score | note | |---|---|---| | cp932 | 114.1 | | | gb18030 | 100.0 | | | cp1252 | 90.4 | contains U+FFFD: original bytes are already lost for those characters | ## Changed lines (6 of 6) | line | as read (wrong) | repaired | |---|---|---| | 1 | `���i�R�[�h,���i��,�P��,����,�S��` | `商品コード,商品名,単価,数量,担当` | | 2 | `A-1001,��i�X�Y�j,120,30,�c��` | `A-1001,りんご(青森産),120,30,田中` | | 3 | `A-1002,�݂���i���Q�Y�j,80,45,����` | `A-1002,みかん(愛媛産),80,45,佐藤` | | 4 | `B-2001,�Β� 500ml,150,12,���` | `B-2001,緑茶 500ml,150,12,鈴木` | | 5 | `B-2002,�ق����� 500ml,150,8,���` | `B-2002,ほうじ茶 500ml,150,8,鈴木` | | 6 | `C-3001,�̂�ٓ�,450,20,����` | `C-3001,のり弁当,450,20,高橋` | --- Produced with `mojibake-repair` (MIT, https://github.com/barnascuhel972-arch/mojibake-repair). Anyone can reproduce every number above by running the same command on the same input file.
4. 自分で検算する
検算ページに元ファイルと修復後ファイルを入れると、6 種類の符号化で「元のバイト列をこの符号化で読むと、修復後の文字列に一致するか」を調べます。一致すれば、中身は一切変わっていません(文字を作り足しても、数字を打ち直してもいない)。
- sales_sjis.csv(元のバイト列)
- sales.utf8.csv(修復後)
- report.md(レポート)
同じ処理をあなたのファイルで: $10(読めていなければ無料)
1 MB までのファイル(または先頭 20 行)を送っていただければ、修復ファイル・レポート・検算リンクをお返しします。uGig で注文(カードまたは USDC)。