Comma-Separated Values (.csv)

RFC 标准

Comma-Separated Values (CSV) is a ubiquitous plain-text format for tabular data, where each line represents a data record and fields are separated by delimiter characters.

将 XLSX 转换为 CSV

免费的浏览器端 XLSX 转 CSV 转换器。在您的设备上即时转换文件。

在线压缩 CSV

100% 浏览器本地私密压缩 — 文件永不离开您的设备

检查与元数据

操作系统和文件分析器通过检查开头的二进制字节序列来识别 CSV 文件:

选择或拖放文件

选择或将文件拖放到此处

100% 浏览器端私密转换 - 文件绝不会离开您的设备

或粘贴 Ctrl+V
零网络传输隐私保证: 上传至外部服务器的数据为 0 字节。所有处理均在您的浏览器沙箱中本地完成。

字节级文件头签名 (Magic Bytes)

操作系统和文件分析器通过检查开头的二进制字节序列来识别 CSV 文件:

十六进制签名 (偏移量 0):

Plain Text

ASCII 表示形式: ASCII / UTF-8

标准化: RFC 4180 / IETF

技术规格

容器架构Delimited flat text file representing tabular data rows and columns
压缩方式Gzip / Deflate achieves 85%-95% compression on repetitive tabular records
字节序UTF-8 text stream (optional UTF-8 BOM EF BB BF used by Excel)
色彩空间Not applicable
通道与结构Row records delimited by CRLF with columns delimited by commas
最大尺寸Unbounded; streamable to gigabytes without loading entire file in memory
透明度Not applicable
流式传输与渐进式加载Native line-by-line stream processing supported by all data pipelines

技术对比矩阵:CSV 对比同类产品

技术属性CSV (当前)Excel (XLSX)ParquetJSON
File TypePlain text flat tableZipped XML spreadsheetBinary columnar storageHierarchical text
Multiple SheetsNo (single flat table only)Yes (multiple workbooks and sheets)Partition-based storageNested arrays and objects
Data TypesUntyped raw textTyped cells, formulas, formattingStrict binary column typesPrimitive types (string, number, bool)
Big Data AnalyticsSlow (requires reading every row linearly)Not suitable for big dataUltra-fast (column pruning & predicate pushdown)Moderate

常见损坏模式与十六进制恢复指南

⚠️ Columns shift to the right or row counts do not match.

根本原因: A text field containing an unescaped comma without surrounding quotation marks.

恢复方法: RFC 4180 requires fields containing commas to be wrapped in double quotes: "Smith, John".

⚠️ Accented characters render as strange symbols (mojibake like é instead of é) in Excel.

根本原因: Excel opened a UTF-8 CSV assuming the legacy Windows ANSI/CP1252 character encoding.

恢复方法: Prepend the 3-byte UTF-8 Byte Order Mark (0xEF 0xBB 0xBF) to the beginning of the file.

安全分析与解析器攻击向量

CSV files open directly in spreadsheet software like Excel and Google Sheets, exposing users to Formula Injection (CSV Injection) attacks.

已知攻击向量

  • Formula Injection: Cells starting with '=', '+', '-', or '@' executing spreadsheet macros or DDE commands (e.g. '=cmd|' /C calc'!A0').
  • Data exfiltration via HYPERLINK() formulas sending sensitive cell data to remote attacker servers upon click.

防御性最佳实践: When exporting user data to CSV, prepend a single quote (') or tab to any cell starting with '=', '+', '-', or '@' to force plain text rendering in Excel.

历史渊源与里程碑

2005IETF publishes RFC 4180, establishing the formal specification for CSV files.
1972IBM Fortran (H Extended) compiler implements comma-delimited input/output.

核心优势与特点

  • Maximum simplicity: readable in any text editor and importable into every database and spreadsheet.
  • Extremely fast line-by-line streaming without building a full in-memory DOM.
  • Minimal overhead: no verbose tag syntax or schema definitions.

技术局限与劣势

  • No standard data types: numbers, dates, booleans, and text are all stored as raw strings.
  • No support for multiple sheets, cell formatting, formulas, or metadata.
  • Delimiter conflicts (commas inside text, decimal commas in European locales) cause frequent parsing bugs.

趣味技术冷知识

  • In many European countries where commas are used as decimal points, semicolons (;) are used instead of commas as CSV separators.
  • Microsoft Excel historically required a UTF-8 BOM (0xEF 0xBB 0xBF) to correctly display non-ASCII accented characters.

常见技术问题

What is RFC 4180?

RFC 4180 is the official IETF standard for CSV. It mandates that fields containing commas, line breaks, or double quotes must be enclosed in double quotes, and internal quotes must be escaped by doubling them ("").

Why do CSV files open with corrupted characters in Excel?

Older versions of Microsoft Excel default to the local Windows code page (like Windows-1252) rather than UTF-8 when opening CSV files directly. Adding a UTF-8 BOM (Byte Order Mark) at the start of the file forces Excel to decode UTF-8 correctly.