CSV 方言检测器

「CSV」并不是一种格式。把文件拖进来,看清你手上这份到底是哪种方言 —— 以及它的哪一处会把别人的导入器搞坏。

🔒 你的文件不会离开浏览器。

本地读取,绝不上传。要检测换行符,请拖入文件 —— 粘贴会把换行规范化。

数逗号不叫检测

找分隔符最省事的办法是数第一行里各种分隔符的个数。它偏偏在最常见的真实文件上失效:一份用分号分隔的欧洲导出文件,商品描述里全是逗号。第一行的逗号比分号多,于是猜错,于是每一列都错位。

本工具用每个候选分隔符把整个文件解析一遍 —— 遵守 RFC 4180 的引号规则 —— 再衡量得到的列数有多一致。真正的分隔符会让几乎每一行都得到相同的列数;错的那个只会得到一堆噪声。每个候选的得分都摆出来,所以这个判定你可以核对,而不必信它。

会把导入搞坏的那些东西

本工具执行的全部检查(9 条规则)

CSV-D01找不到一致的分隔符

没有任何候选分隔符能让全文各行的列数一致。要么这根本不是表格数据,要么行已经坏到没有任何解析器会对它的形状达成一致。

修复: 用文本编辑器打开,看前几行 —— 结构通常一眼就能看出来。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-D02分隔符有歧义

不止一种分隔符能解析出说得通的结果。导入器只能猜,而不同的导入器猜法不同 —— 同一份文件在一个工具里正常、在另一个工具里整列错位,就是这么来的。

修复: 用没有歧义的分隔符重新导出,或者在导入设置里显式指明分隔符。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-R01行的字段数参差不齐

有些行的字段数与表头不一致。常见原因是值里有未加引号的分隔符,或者值中间夹了换行 —— 它后面的数据会静默地落进错误的列。

修复: 凡是含分隔符、引号或换行的值,一律加引号。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-E01文件开头有字节序标记(BOM)

文件以 BOM 开头。它不可见,却会粘在第一个列名上 —— 所以表头明明写着 id,导入时却一口咬定 id 这一列不存在。

修复: 另存为「UTF-8」,而不是「带 BOM 的 UTF-8」。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-E02换行符混用

文件里 CRLF 与 LF 两种换行混着用。严格的解析器会把多出来的那个字符当成数据,表现出来就是某些行的最后一列尾部多了个看不见的字符。

修复: 导入前把全文统一成一种换行符。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-E03老式 CR 换行

行尾是孤立的回车符(经典 Mac 风格)。很多现代解析器会把整个文件读成一行。

修复: 转换成 LF 或 CRLF。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-H01第一行可能不是表头

第一行看起来像数据 —— 它含有能当数字解析的值,或者形状与下面各行一样。把它当表头导入,你的第一件商品就变成了列名。

修复: 补一行表头,或者告诉导入器这个文件没有表头。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-H02列名重复或为空

有两列同名,或者某列没有名字。哪一列胜出是未定义的,不同解析器的做法也不一样。

修复: 给每一列一个不重复、且非空的名字。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

CSV-Q01存在加引号的字段

文件对部分值加了引号 —— 这正是让分隔符与换行能出现在数据内部的写法。任何读这份文件的工具都必须遵守 RFC 4180 的引号规则;只按分隔符切分,就会把这些行切坏。

来源: RFC 4180 and the dialects real exporters actually produce. Detection is by column-count consistency across the whole file, not by counting separators in the first line.

关于这些规则。 每一条都有编号、严重级别和通俗解释。每个来源链接都已登记在案,并对线上页面实际复验过,而不是凭印象写上去的. 规则如何编写、测试与保持更新 →