解決Excel打開UTF-8編碼的CSV文件亂碼的問題app
引用自:https://en.wikipedia.org/wiki/Comma-separated_values
ide
「編碼
CSV formats are not limited to a particular character set. They work just as well with Unicode character sets (such as UTF-8 or UTF-16) as with ASCII (although particular programs that support CSV may have their own limitations). CSV files normally will even survive naive translation from one character set to another (unlike nearly all proprietary data formats). CSV does not, however, provide any way to indicate what character set is in use, so that must be communicated separately, or determined at the receiving end (if possible).spa
Databases that include multiple relations cannot be exported as a single CSV file.code
」orm
CSV是一個平面文件,它的編碼方式有多種。好比,MongoDB以UTF-8格式存儲數據,在使用mongoexport導出爲CSV文件時,CSV的編碼即爲UTF-8。(能夠將導出的CSV文件用UltraEdit打開來驗證編碼格式)blog
當直接使用Excel打開UTF-8編碼的CSV文件時會出現亂碼。ip
「ci
Microsoft Excel will open .csv files, but depending on the system's regional settings, it may expect a semicolon as a separator instead of a comma, since in some languages the comma is used as the decimal separator. It also applies some magic, such as reformatting what looks like numbers, eliminating leading + or 0, which breaks phone numbers, or a leading = makes the cell a formula, where function names must be in the opener's local language. Also, many regional versions of Excel will not be able to deal with Unicode in CSV. One simple solution when encountering such difficulties is to change the filename extension from .csv to .txt; then opening the file from an already running Excel instance with the "Open" command, where the user can manually specify the delimiters, encoding, format of columns, etc.get
」
Excel打開CSV文件依賴於系統的區域設置。因爲區域設置的影響,以及CSV文件不一樣的實現,那麼Excel須要以正確的方式來打開CSV文件。咱們以從MongoDB導出的UTF-8格式編碼的CSV文件爲例:
1. 打開Excel應用程序。
2. 點擊「數據」菜單的「自文本」:
3. 選擇CSV文件,點擊「導入」,出現「文本導入嚮導」對話框。
從上面的默認設置我懷疑Excel默認以「Windows(ANSI)」打開CSV,未識別編碼。
4. 文件類型選擇「分割符號」,文件原始格式選擇「65001:Unicode(UTF-8)」,勾選「數據包含標題」,點擊下一步。
5. 分割符號去掉「Tab鍵」而勾選「逗號」,點擊「下一步」。
6. 列數據格式根據須要選擇,這裏保持常規,點擊「完成」。
7. 彈出「導入數據」對話框,咱們選擇「現有工做表」,點擊「肯定」。
8. 數據顯示正常。