gpt4 book ai didi

windows - 哪种编码可以在 Mac 和 Windows 上使用 Excel 正确打开 CSV 文件?

转载 作者:可可西里 更新时间:2023-11-01 11:52:54 26 4
gpt4 key购买 nike

我们有一个网络应用程序可以导出包含 UTF-8 外来字符的 CSV 文件,没有 BOM。 Windows 和 Mac 用户在 Excel 中都会收到乱码。我尝试使用 BOM 转换为 UTF-8; Excel/Win 没问题,Excel/Mac 显示乱码。我正在使用 Excel 2003/Win、Excel 2011/Mac。这是我尝试过的所有编码:

Encoding  BOM      Win                            Mac
-------- --- ---------------------------- ------------
utf-8 -- scrambled scrambled
utf-8 BOM WORKS scrambled
utf-16 -- file not recognized file not recognized
utf-16 BOM file not recognized Chinese gibberish
utf-16LE -- file not recognized file not recognized
utf-16LE BOM characters OK, same as Win
row data all in first field

最好的是带 BOM 的 UTF-16LE,但 CSV 无法识别。字段分隔符是逗号,但分号不会改变任何东西。

是否有任何编码在两个世界都有效?

最佳答案

Excel 编码

我发现 WINDOWS-1252 编码在处理 Excel 时最不令人沮丧。由于它基本上是微软自己的专有字符集,因此可以假设它可以在 Mac 和 Windows 版本的 MS-Excel 上运行。这两个版本至少包含一个相应的“文件来源”或“文件编码”选择器,可以正确读取数据。

根据您的系统和您使用的工具,此编码也可以命名为 CP1252ANSIWindows (ANSI)MS-ANSI 或只是 Windows,以及其他变体。

此编码是 ISO-8859-1(又名 LATIN1 和其他)的超集,因此您可以回退到 ISO-8859-1 如果你因为某些原因不能使用 WINDOWS-1252。请注意,ISO-8859-1 缺少 WINDOWS-1252 中的一些字符,如下所示:

| Char | ANSI | Unicode | ANSI Hex | Unicode Hex | HTML entity | Unicode Name                               | Unicode Range            |
| € | 128 | 8364 | 0x80 | U+20AC | € | euro sign | Currency Symbols |
| ‚ | 130 | 8218 | 0x82 | U+201A | ‚ | single low-9 quotation mark | General Punctuation |
| ƒ | 131 | 402 | 0x83 | U+0192 | ƒ | Latin small letter f with hook | Latin Extended-B |
| „ | 132 | 8222 | 0x84 | U+201E | „ | double low-9 quotation mark | General Punctuation |
| … | 133 | 8230 | 0x85 | U+2026 | … | horizontal ellipsis | General Punctuation |
| † | 134 | 8224 | 0x86 | U+2020 | † | dagger | General Punctuation |
| ‡ | 135 | 8225 | 0x87 | U+2021 | ‡ | double dagger | General Punctuation |
| ˆ | 136 | 710 | 0x88 | U+02C6 | ˆ | modifier letter circumflex accent | Spacing Modifier Letters |
| ‰ | 137 | 8240 | 0x89 | U+2030 | ‰ | per mille sign | General Punctuation |
| Š | 138 | 352 | 0x8A | U+0160 | Š | Latin capital letter S with caron | Latin Extended-A |
| ‹ | 139 | 8249 | 0x8B | U+2039 | ‹ | single left-pointing angle quotation mark | General Punctuation |
| Π| 140 | 338 | 0x8C | U+0152 | Π| Latin capital ligature OE | Latin Extended-A |
| Ž | 142 | 381 | 0x8E | U+017D | | Latin capital letter Z with caron | Latin Extended-A |
| ‘ | 145 | 8216 | 0x91 | U+2018 | ‘ | left single quotation mark | General Punctuation |
| ’ | 146 | 8217 | 0x92 | U+2019 | ’ | right single quotation mark | General Punctuation |
| “ | 147 | 8220 | 0x93 | U+201C | “ | left double quotation mark | General Punctuation |
| ” | 148 | 8221 | 0x94 | U+201D | ” | right double quotation mark | General Punctuation |
| • | 149 | 8226 | 0x95 | U+2022 | • | bullet | General Punctuation |
| – | 150 | 8211 | 0x96 | U+2013 | – | en dash | General Punctuation |
| — | 151 | 8212 | 0x97 | U+2014 | — | em dash | General Punctuation |
| ˜ | 152 | 732 | 0x98 | U+02DC | ˜ | small tilde | Spacing Modifier Letters |
| ™ | 153 | 8482 | 0x99 | U+2122 | ™ | trade mark sign | Letterlike Symbols |
| š | 154 | 353 | 0x9A | U+0161 | š | Latin small letter s with caron | Latin Extended-A |
| › | 155 | 8250 | 0x9B | U+203A | › | single right-pointing angle quotation mark | General Punctuation |
| œ | 156 | 339 | 0x9C | U+0153 | œ | Latin small ligature oe | Latin Extended-A |
| ž | 158 | 382 | 0x9E | U+017E | | Latin small letter z with caron | Latin Extended-A |
| Ÿ | 159 | 376 | 0x9F | U+0178 | Ÿ | Latin capital letter Y with diaeresis | Latin Extended-A |

请注意,缺少欧元符号。此表可在 Alan Wood 找到.

转化

每种工具和语言的转换方式都不同。但是,假设您有一个文件 query_result.csv,您知道它是 UTF-8 编码的。使用 iconv 将其转换为 WINDOWS-1252:

iconv -f UTF-8 -t WINDOWS-1252 query_result.csv > query_result-win.csv

关于windows - 哪种编码可以在 Mac 和 Windows 上使用 Excel 正确打开 CSV 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6588068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com