离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
Word 转 CSV——离线、表格首行当列名、不上传Word tables to CSV offline — the first row names columns
把 Word 里的表拉成 CSV 要过三道:`docx>html` 用 mammoth 读出文档体(显式 styleMap 把 Heading 1 到 4 映射成 `h1` 到 `h4`、Title 与 Subtitle 分别成 `h1.title` 与 `h2.subtitle`,字符样式认 Strong 与 Emphasis,列表按 `ul` / `ol` / `li` 重开),内嵌图片走 `mammoth.images.imgElement` 读成 data URI;结果过 DOMPurify 的 html profile。如果这一遍什么都没拿到,还有第二条路:`extractAltChunkHtml` 从 MHT 里把正文捞回来——**这个扩展自己产出的 `.docx` 正是那种容器**,所以 HTML→Word 的结果可以再被读回去。两条路都空则报 `errors.docxEmpty`(与打不开的 `errors.docxParse` 是两种报告)。`html>json` 取表格:**第一行给出键名,其余每行一条记录**,这一步不看它在原文里是不是标题行;行与格都按「只看这张表自己」的作用域读,所以套在单元格里的表不会被摊平成外层数据行——但**它的存在算第二张表**,见 limits。`json>csv` 把数组摊平:列是所有记录键名的并集,某行没有的键留空格,元素里没有键可挂的(顶层标量、嵌套数组)写进合成的 `_value` 列而不是丢掉;嵌套对象在其单元里写成 JSON 文本;产物开头带 UTF-8 BOM。全程在这个标签页里完成,只有 storage 权限;净化那一步之后还会 `stripRemoteResources`,因为 altChunk 捞回来的正文不是本项目写的标记——实测过一份 `afchunk.mht` 里带远程 `<img>` 的文档,不剥就会在你打开产物时发出请求。Pulling a Word table into CSV passes three doors: `docx>html` reads the body with mammoth (an explicit styleMap maps Heading 1–4 to `h1`–`h4`, Title and Subtitle to `h1.title` and `h2.subtitle`, the Strong and Emphasis character styles are honoured, lists reopen as `ul` / `ol` / `li`) and embedded pictures come in through `mammoth.images.imgElement` as data URIs, then the result passes DOMPurify’s html profile. If that pass yields nothing there is a second one: `extractAltChunkHtml` recovers the body from the MHT — **and the `.docx` files this extension itself writes are exactly that kind of container**, so an HTML→Word result can be read back. When both passes come up empty the route reports `errors.docxEmpty`, deliberately different from the cannot-open `errors.docxParse`. `html>json` then lifts the table: **the first row supplies the keys and every later row is one record**, and that step does not ask whether the source row was a heading; rows and cells are read in a “this table only” scope, so a table nested inside a cell is not flattened into the outer rows — but its presence counts as a second table, see limits. `json>csv` spreads the array: columns are the union of every record’s keys, a key a row lacks becomes a blank cell, elements with no keys to hang on (top-level scalars, nested arrays) go into a synthetic `_value` column instead of being dropped, nested objects are written as JSON text inside their cell, and the file starts with a UTF-8 BOM. All of it happens in this tab on the storage permission, and after sanitising comes `stripRemoteResources`, because the altChunk body is markup this project never wrote — measured on a document whose `afchunk.mht` carried a remote `<img>`: unstripped, the artifact requested that URL when opened.
这条链路怎么走How the route runs
Word (.docx)Word (.docx) HTMLHTML JSONJSON CSVCSV
共 3 步,由扩展的路径搜索自动选出,中间产物不落盘。3 steps, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 第一行给列名、其余行给记录:这一步只看表格结构,不要求原文把首行标成标题行The first row names the columns and the rest are records: structure decides, no heading markup required
- 值按写下的字符落地:`00424`、`1/2`、`2024-01-05` 都不被推断成数字或日期Values land as the characters written, so `00424`, `1/2` and `2024-01-05` are not inferred into numbers or dates
- 没有键可挂的元素进合成 `_value` 列,一千条记录出一千行,不静默少行Elements with no keys go into a synthetic `_value` column, so 1 000 records write 1 000 rows instead of silently losing some
- 本扩展自己写的 `.docx` 能被读回:HTML→Word 与 Word→HTML 是可来回的一对The `.docx` files this extension writes can be read back: HTML→Word and Word→HTML are a round trip
如实说明的限制What it does not do
- 两份表格就撞闸:文档里有两张以上 `<table>` 且至少一张带数据行时,中间那步交出的是分组对象——键取同序号的那个 `<h2>` 文字,那里没有对应标题时是 `Sheet2` 这类名字——而 CSV 那一步只接受数组,界面报「JSON 内容必须是包含数据的数组才能转换为 CSV」——请一张表一个文件Two tables trip the gate: with more than one `<table>` and at least one carrying data rows, the middle step hands over a grouped object — keyed by the `<h2>` at the same index, or a `Sheet2`-style name where there is none — and the CSV step accepts arrays only, so the interface reports “JSON must be an array containing data to convert to CSV” — one table per file
- 表格套在单元格里也算两张:它不会污染数据行,但会让整批失败A table nested in a cell also counts as the second one: it does not pollute the data rows, but it fails the batch
- 合并区不展开:被 `colspan` / `rowspan` 覆盖的位置不产生值,那一行的列会左移Merged ranges are not expanded: positions covered by `colspan` / `rowspan` produce no value, so that row shifts left
- 段落、页眉页脚、脚注正文与批注没有单元格可放,不进结果;但脚注的引用标记(形如 `[1]`)会留在所在单元格的值里,插入修订(`w:ins`)的文字也按正文读出——只有删除修订会消失Paragraphs, headers and footers, footnote text and comments have no cell to sit in and do not appear — though a footnote reference such as `[1]` stays inside the value of the cell carrying it, and inserted revisions (`w:ins`) are read as ordinary text while only deletions vanish
- 打不开不是空文档:解不出容器报 `errors.docxParse`,解开了但没有可转内容报 `errors.docxEmpty`,两种说法在界面上分开Unreadable is not empty: a container that cannot be parsed reports `errors.docxParse`, while one that parses with nothing convertible reports `errors.docxEmpty`, and the interface keeps them apart
实操提示Working with it
- 要工作簿而不是文本:Word→Excel 是同一条链再加一步取数与格式钉格For a workbook rather than text: Word to Excel is this chain plus the typing and format-pinning step
- 要保留版面给人看:Word→HTML、Word→PDF 或 Word→Markdown,结构与文字都在For something that reads like the document: Word to HTML, PDF or Markdown, which carry its structure and words
- 只要文档里的文字本身:Word→TXT 按阅读顺序抽正文,比这里逐格取值更贴近页面For the words themselves: Word to TXT takes the body in reading order, which sits closer to the page than cell-by-cell values
常见问题Questions people actually ask
我的 Word 文档里有两张表,为什么直接报错?My document has two tables — why does it just fail?
因为中间那一步为了不把两张表的列混在一起,交出的是「小标题 → 该表数据」的对象,而对象过不了 CSV 那道「必须是数组」的闸。这不是没做完,而是不肯猜哪张表才是你要的。把两张表分别另存成两个文档,各转一次即可。Because the middle step, rather than merge two tables’ columns, hands over an object of “heading → that table’s rows”, and an object cannot pass the CSV step’s arrays-only gate. That is a refusal to guess which table you meant, not unfinished work: save the two tables as two documents and convert each.
表里的日期和编号会被改写吗?Will dates and ids in the table be rewritten?
不会。中间那步取到的单元文字是字符,这一层不做类型猜测——猜就把 `00424` 变成 `424`、把 `1/2` 变成某个日期。需要可计算的数字,请走 Word→Excel:那条链按「字节能逐字回来」的规则把确实是数字的格子还原成数字。No. Cells arrive as characters and this layer guesses nothing — guessing is how `00424` becomes `424` and `1/2` becomes a calendar day. For summable numbers take Word to Excel, which restores the number type only where the bytes come back exactly.
为什么标题与段落都不在 CSV 里?Why are my headings and paragraphs missing?
因为 CSV 只有一格一格的值:文档结构在中间那步变成 HTML 后被读成表格数据,标题、正文与批注没有能落值的列。要留结构请用 Word→Markdown、Word→HTML 或 Word→TXT;这里交付的是表格,不是文档。Because CSV holds values in cells and nothing else: the document becomes HTML and is then read as table data, so headings, body text and comments have no column to land in. For structure take Word to Markdown, HTML or TXT — this route delivers a table, not a document.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。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