离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
TXT 转 CSV——离线、JSON 数组变表格、不上传TXT to CSV offline — a JSON array becomes a table
这条路和 TXT→JSON 共用第一步(文本整段包进 `<pre>`),中间那步把 `<pre>` 里的文字当 JSON 解析,最后由 JSON→CSV 把数组摊成表。所以成立的条件写在两步里:**文本得是一段 JSON 数组**。对象数组最顺:表头是所有记录键名的并集,某条记录没有的键留空格而不是整体左移;元素里没有键可挂(顶层是字符串或数字、或数组套数组)时,会加一列合成的 `_value` 把它们接住——本项目对这条的判断是「1000 条记录只写出 980 行还报成功」比多一列难看严重得多,所以宁可多一列。嵌套对象与数组在其单元里写成 JSON 文本,值不会被拆成多行。写出的 CSV 带 UTF-8 BOM(`json→csv` 那一步加的三个字节),数字按值写而不是按显示文本写:`1727000000000` 出来是完整一串,不会变成 `1.727E+12`;反过来,以 `=`、`+`、`-`、`@` 开头的**字符串**值会带一个防执行的前缀,因为导出后被人双击打开时那些字符正是公式的起手式。日期串不猜格式:`2024-01-05` 与 `1/2` 都按写下的字符落地。全程在这个标签页里,只有 storage 权限。This route shares its first step with TXT to JSON (the text is wrapped whole in a `<pre>`), the middle step parses that `<pre>` as JSON, and JSON to CSV spreads the array into a table. So the conditions sit in those two steps: **the text has to be a JSON array**. An array of objects travels best — the header is the union of every record’s keys, and a key one record lacks becomes a blank cell rather than shifting the row left. When an element has no keys to hang anything on (top-level strings or numbers, arrays inside arrays), a synthetic `_value` column catches them: this project’s position is that 1 000 records writing 980 rows while reporting success is far worse than one extra column. Nested objects and arrays are written as JSON text inside their cell, so a value is never split across rows. The CSV carries a UTF-8 BOM (the three bytes the JSON to CSV step writes) and writes values rather than display text: `1727000000000` lands as the whole string of digits instead of `1.727E+12`, while a **string** beginning with `=`, `+`, `-` or `@` gains an anti-execution prefix, because those are exactly the characters a formula starts with once someone double-clicks the file. Dates are not guessed: `2024-01-05` and `1/2` keep the characters written. All of it in this tab, storage permission only.
这条链路怎么走How the route runs
纯文本 (TXT)plain text (TXT) HTMLHTML JSONJSON CSVCSV
共 3 步,由扩展的路径搜索自动选出,中间产物不落盘。3 steps, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 表头是所有记录键名的并集:某条记录没有的键留空格,后面的列不会整体左移The header is the union of every record’s keys, so a key missing from one record leaves a blank cell instead of shifting its columns
- 没有键可挂的元素写进合成的 `_value` 列——顶层标量与嵌套数组都不丢,1000 条记录就出 1000 行Elements with no keys go into a synthetic `_value` column — top-level scalars and nested arrays are neither dropped nor silently skipped, so 1 000 records make 1 000 rows
- 嵌套对象与数组在其单元里写成 JSON 文本,一条记录占一行Nested objects and arrays are written as JSON text inside their cell, keeping one record per row
- 产物带 UTF-8 BOM,数字按值写出:时间戳与雪花 ID 保持完整一串,不会变成科学计数The artifact carries a UTF-8 BOM and writes values, not display text: timestamps and snowflake IDs stay the full string instead of going exponential
如实说明的限制What it does not do
- 文本必须是合法 JSON **数组**:对象会在中间那步被拒(界面报「JSON 内容必须是包含数据的数组才能转换为 CSV」),普通文章连第一步都过不去The text must be a valid JSON **array**: an object is refused by the middle step, with the interface reporting “JSON must be an array containing data to convert to CSV”, and prose never gets past the first
- 空数组 `[]` 与全空对象 `[{}]` 报错而不是给一份只有表头、没有内容的 CSVAn empty array `[]` or an all-empty-object `[{}]` reports failure rather than handing back a header-only file
- 换行不带着走:` ` 在第一步变成 `<br>`,JSON 语法不依赖它所以照常解析,但你手工排的版式不会保留Line breaks do not travel: the first step turns ` ` into `<br>`, which JSON does not depend on, so your own layout is not preserved
- 以 `=`、`+`、`-`、`@` 开头的字符串值会带一个前导的防执行字符;被判为数字的负数不受影响A string value starting with `=`, `+`, `-` or `@` gains a leading anti-execution character; negative numbers typed as numbers are untouched
- 值里的日期不会被识别:`2024-01-05` 出来还是那串字符——这一族刻意不猜格式,因为猜就把 `1/2` 变成了 2001 年 1 月 2 日Dates inside values are not recognised: `2024-01-05` stays those characters, because guessing is how `1/2` became 2 January 2001
实操提示Working with it
- 只要一份排好版的 JSON:走 TXT→JSON,同一份输入、少一步For tidy JSON only: TXT to JSON is the same input one step shorter
- 要的是工作簿而不是 CSV:TXT→Excel 走同一条链的最后一步,并按「值回得来才是数字」的规则取数For a workbook instead of CSV: TXT to Excel shares this chain’s last step and applies the round-trip typing rule
- 文本不是 JSON:这条链无法凭空造出列,请看 TXT→HTML / PDF / Word 那几条保留排版的路For text that is not JSON: no columns can be invented here, so take the TXT to HTML, PDF or Word routes that keep the layout
常见问题Questions people actually ask
我的 txt 每行一条记录,为什么不按行切成列?My text file is one record per line — why not split it by lines?
因为「按行切」要先猜列在哪里:同一个文件里可能是制表符、多个空格、逗号或竖线,猜错就整列错位,而且没有一种猜测能让所有 txt 都对。这条路只认 JSON 那种自带结构的数据;其他文本请先另存为 CSV 或用能明确分隔的格式。Because splitting by lines means guessing where the columns are: the same file might use tabs, runs of spaces, commas or pipes, and a wrong guess shifts every column with no rule that works for all text. This route reads only data that arrives structured, i.e. JSON; save as CSV first, or use a format with an explicit delimiter.
`_value` 那一列是什么,为什么会出现?What is that `_value` column and why does it appear?
它是给「没有键可挂」的元素准备的合成列:`["a","b"]` 这种标量数组、或 `[{"a":1},"note"]` 里那条 `"note"`。没有它,这些元素只能被丢掉或让整行列数错位——所以宁可多一列。若你的记录本来就用了 `_value` 这个名字,合成列会退到 `_value_2`,两者都保住。It is the synthetic column for elements with no keys to hang on: a scalar array like `["a","b"]`, or the `"note"` in `[{"a":1},"note"]`. Without it those elements would be dropped or would shift every row’s columns, so one extra column is the cheaper outcome. If your records already use `_value`, the synthetic one becomes `_value_2` and both survive.
Excel 打开这份 CSV 会乱码吗?Will Excel open this CSV as mojibake?
产物开头带三个字节 `EF BB BF`——那是 UTF-8 BOM,由 JSON→CSV 那一步写上。带 BOM 是让读表格的软件认出 UTF-8 的常见做法;若你的软件仍按地区代码页解释字节,用它的导入向导手工指定 UTF-8 更稳。The artifact opens with the three bytes `EF BB BF` — a UTF-8 BOM, written by the JSON to CSV step. Emitting one is the usual way to help a spreadsheet reader settle on UTF-8; if your reader still applies a regional code page, name UTF-8 in its import wizard.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。No account and no network: install the extension, click its icon, and the workbench opens in a new tab reading straight off your disk.
从 Chrome 应用商店安装Install from the Chrome Web Store 安装步骤Install steps GitHub 源码Source on GitHub