博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决Excel打开UTF-8编码的CSV文件乱码的问题
阅读量:7107 次
发布时间:2019-06-28

本文共 2014 字,大约阅读时间需要 6 分钟。

解决Excel打开UTF-8编码的CSV文件乱码的问题

引用自:

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).

Databases that include multiple relations cannot be exported as a single CSV file.

CSV是一个平面文件,它的编码方式有多种。比如,MongoDB以UTF-8格式存储数据,在使用mongoexport导出为CSV文件时,CSV的编码即为UTF-8。(可以将导出的CSV文件用UltraEdit打开来验证编码格式)

当直接使用Excel打开UTF-8编码的CSV文件时会出现乱码。

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.

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. 数据显示正常。

转载地址:http://cjphl.baihongyu.com/

你可能感兴趣的文章
【读书笔记】数据库逻辑结构
查看>>
洛谷——1616 疯狂的采药(完全背包)
查看>>
Nginx脚本方式切割日志
查看>>
朋友圈H5营销怎么玩?又见情感营销
查看>>
$(window).scroll不能在样式内写overflow属性
查看>>
centos 6.0 dhcp 报错及解决
查看>>
查看linux 版本
查看>>
我的友情链接
查看>>
TNS-12537: TNS:connection closed ORA-609错误处理
查看>>
记我的第一次腾讯游戏策划面试
查看>>
2017.12.21 2周4次课
查看>>
VMware ESXI 虚拟磁盘工具 - vmkfstools
查看>>
决心书
查看>>
inux命令之dot - 绘制DOT语言脚本描述的图形
查看>>
Row Cache For InnoDB 第二版优化(附带安装和配置说明)
查看>>
第十一课-布局反射器
查看>>
我的友情链接
查看>>
linux 管理参数调节
查看>>
BOM详解
查看>>
2017-3-27日碎碎念
查看>>