离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
Word 转 Excel——离线、一张表进一张工作表、不上传Word to Excel offline — one table, values kept
四步,前两步与 Word→CSV 完全相同:`docx>html` 用 mammoth 读出文档(Heading 1 到 4 成 `h1` 到 `h4`、Title 与 Subtitle 成带 class 的 `h1` / `h2`、列表按 `ul` / `ol` / `li` 重开、内嵌图片成 data URI),净化后成一份自带样式表的 HTML,捞不到正文时再从 MHT altChunk 里恢复;`html>json` 取表格,**第一行给出键名**、其余行成记录,行列都限定在「这张表自己」的作用域内;`json>csv` 摊成表;`csv>xlsx` 写工作簿。真正决定产物的是最后一步:读 CSV 用 `raw: true`,SheetJS 的类型推断器碰不到数据,`00424` 不缩成 `424`、`2024-01-05` 不变成序列号;随后只有一道规则把该是数字的格子还回去——十进制形状、`String(Number(x)) === x` 逐字节回得来、有效数字不超过 15 位。16 位以上刻意留在文本,因为表格软件只渲染 15 位有效数字,卡号那一级编号一旦成数就会被读成 `4.11111111111111E+15`。仍是文本的格子再加公式护栏,并把数字格式钉成文本——写出的 `xl/styles.xml` 里那一格就是内置格式号 49。产物是一张工作表,表名沿用读取 CSV 时得到的那一个。两条要照实说的边界:文档里有两张表(含套在单元格里的那种)时,中间那步交出的是分组对象,CSV 那步只接受数组,整批报「JSON 内容必须是包含数据的数组才能转换为 CSV」;合并区被 `colspan` / `rowspan` 覆盖的位置不产生值,那一行的列会左移。全程离线、只有 storage 权限,净化之后仍会剥掉远程引用。Four steps, the first two identical to Word to CSV: `docx>html` reads the document with mammoth (Heading 1–4 become `h1`–`h4`, Title and Subtitle become classed `h1` / `h2`, lists reopen as `ul` / `ol` / `li`, embedded pictures arrive as data URIs), the result is sanitised and wrapped in the bundled stylesheet, and an empty pass falls back to the MHT altChunk; `html>json` lifts the table, **first row naming the keys**, later rows becoming records, all read inside a “this table only” scope; `json>csv` spreads it; `csv>xlsx` writes the workbook. The last step decides the artifact: the CSV is read with `raw: true`, so SheetJS’s inferrer never touches the data — `00424` does not shrink and `2024-01-05` does not become a serial — and one rule alone returns the number type: decimal shape, `String(Number(x)) === x` giving the exact characters back, at most 15 significant digits. Sixteen and above stay text deliberately, because a spreadsheet renders 15 significant digits and a card number turned into a value reads back as `4.11111111111111E+15`. Cells that remain text also get the formula guard and a pinned text number format — that cell carries the built-in format id 49 in the written `xl/styles.xml`. The output is a single worksheet, named whatever the CSV read produced. Two boundaries stated plainly: with two tables in the document (including one nested inside a cell) the middle step hands over a grouped object, the CSV step accepts arrays only, and the batch fails with “JSON must be an array containing data to convert to CSV”; and merged ranges are not expanded, so positions covered by `colspan` / `rowspan` produce no value and that row shifts left. Everything runs in this tab on the storage permission, and remote references are stripped after sanitising.
这条链路怎么走How the route runs
Word (.docx)Word (.docx) HTMLHTML JSONJSON CSVCSV Excel (.xlsx)Excel (.xlsx)
共 4 步,由扩展的路径搜索自动选出,中间产物不落盘。4 steps, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 数字只在字节能逐字回来时才是数字:`1727000000000` 可求和,`00424`、`1/2`、`2024-01-05` 保持原字符A value is a number only when its bytes come back exactly: `1727000000000` becomes summable while `00424`, `1/2` and `2024-01-05` stay as written
- 16 位以上的编号留在文本,并钉住文本格式(写出的那一格是内置格式号 49)Identifiers of 16 digits or more stay text, pinned to a text number format (the written cell carries the built-in format id 49)
- 列取所有记录键名的并集:某行缺的键留空格;比表头多出的单元格在取表那一步就被丢掉,所以后面几列不会错位Columns are the union of every record’s keys and a missing key is a blank cell, while cells beyond the header row are dropped at the table step, so later columns cannot shift
- 一张表进一张工作表:中间那份 CSV 只有一个表,产物就是单 sheet,表名沿用读取结果One table, one worksheet: the intermediate CSV has a single table, so the sheet count is one and its name is whatever the read produced
如实说明的限制What it does not do
- 两张表就撞闸:只要至少一张带数据行,交出的是分组对象,过不了「只接受数组」那一步——请一张表一个文档Two tables with data rows trip the gate: the grouped object cannot pass the arrays-only step, so keep one table per document
- 段落、页眉页脚、脚注正文与批注不进工作簿;插入修订的文字与脚注引用标记会留在它们所在单元格的值里Paragraphs, headers and footers, footnote text and comments do not reach the workbook, while inserted revisions and footnote references stay inside the value of the cell carrying them
- 合并区不展开,被覆盖的位置不产生值;嵌套表算第二张表Merged ranges are not expanded and covered positions produce no value; a nested table counts as the second table
- 值在中间那步全是字符串,是否还原成数字由最后一步那三条规则决定:`1,234.50`、`¥100`、`45%`、`+33` 都不是十进制形状,留在文本Values are strings in the middle step and the final rule of three decides whether one comes back: `1,234.50`, `¥100`, `45%` and `+33` are not decimal-shaped and stay text
- 本扩展写的 `.docx` 用的是 altChunk 容器,读回时会走恢复那一条路;用其他编辑器写的文档则看它自己的表格结构能否被 mammoth 认出The `.docx` files this extension writes carry an altChunk container and are read back through the recovery path; documents from other editors depend on whether mammoth recognises their table structure
实操提示Working with it
- 只要一份文本表格:Word→CSV 是同一条链的前三步,产物是带 BOM 的 CSVFor a text table only: Word to CSV is the first three steps of this chain, ending in a BOM’d CSV
- 要一份读起来像原文档的:Word→PDF、Word→HTML 或 Word→MarkdownFor something that reads like the document: Word to PDF, HTML or Markdown, which carry its structure and text
- 只想读回值不要类型判断:Word→JSON,那里值全是字符串、结构按 `<h2>` 分组For values without any typing decision: Word to JSON, where everything is a string and grouping follows the `<h2>` text
常见问题Questions people actually ask
为什么我的 Word 表转成 Excel 后没有公式与格式?Why did my Word table come out with no formulas or formatting?
因为这条链搬运的是格子里的值:Word 表格里的内容被读成文字,再以「值是否逐字节回得来」决定要不要还成数字。文档里的样式、条件格式与计算结果都不是它的取数对象——它交付的是一张可算的数据表,不是一份排版副本。Because this chain carries values: the cells are read as text, and a number type returns only where the bytes round-trip. Styles, conditional formatting and computed results in the document are not what it extracts — what arrives is cell values, not a copy of the layout.
编号前面的零会丢吗?Do leading zeros in my ids survive?
不会。`00424` 与 16 位账号都留在文本形态并被钉住文本格式(写出的那一格用内置格式号 49),所以那一格存下来的就是文本形态的值。代价是那些格子里存的是字符而不是数值;这是本项目在「保住编号」与「让它成数」之间刻意选的前者。No. `00424` and a 16-digit identifier stay text and are pinned to a text format (the written cell uses the built-in format id 49), so what is stored there is text, not a number. The price is that those cells hold characters rather than a numeric value; that is the trade this project deliberately takes in favour of keeping identifiers intact.
两份表格能分别落到两个 sheet 吗?Can two tables land on two worksheets?
不能。这条链一次吃得下一张表:多张表在中间那步是分组对象,CSV 那步不接受;而写工作簿那步读的也只有一份 CSV。要两份,请把两张表分成两个文档各转一次,各自得到一份工作簿。Not on this route: it eats one table at a time, since several become a grouped object that the CSV step rejects, and the writer reads a single CSV anyway. Split the tables into two documents and convert each; you then have one workbook per table.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。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