离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
HTML 转 Word(.docx)——离线打包,结构跟着走HTML to Word (.docx) offline — structure survives
网页存档、导出笔记、内部系统里复制出来的一段 HTML,要交给只收 Word 的人。这条路径用 html-docx-js 把净化后的 HTML 打进 .docx 的 altChunk,Word 打开文件时按自己的 HTML 子集渲染成段落——文字可选中、可编辑、可批注。打包前有两道处理:内联 SVG 先栅格化成 PNG(净化器的 html 配置不含 svg 标签,不先转换会把图整块删掉),随后剥掉所有远程子资源,包括 `//host/x.png` 这种协议相对地址。链路完全在本机完成。A saved page, an exported note, a block of HTML copied out of an internal tool — and the recipient only accepts Word. This route packs sanitized HTML into the .docx as an altChunk, which Word renders into paragraphs when the file is opened: text stays selectable, editable and commentable. Two passes run before packing: inline SVG is rasterized to PNG first (the sanitizer’s html profile carries no svg tag, so skipping that step would delete the diagram outright), and every remote subresource is then stripped, protocol-relative `//host/x.png` included. The whole route runs locally.
这条链路怎么走How the route runs
HTMLHTML Word (.docx)Word (.docx)
共 1 步,由扩展的路径搜索自动选出,中间产物不落盘。1 step, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 标题、段落、有序与无序列表、表格、引用、加粗斜体与链接,成为 Word 里的真实内容(不是整页截图)Headings, paragraphs, ordered and unordered lists, tables, quotes, emphasis and links arrive as real Word content — not as a screenshot of the page
- 内联 SVG 先转成 PNG 再打包,图示不会在净化那一步被整块删掉Inline SVG is turned into PNG before packing, so a diagram is not deleted wholesale by the sanitizer
- 纯文本链接保留:`<a href>` 是正文内容,不是子资源,剥离时不碰它Plain links survive: an `<a href>` is content, not a subresource, and the strip pass leaves it alone
- 一批最多 200 个文件、单个 100 MB,可与其它源格式混批Up to 200 files per batch at 100 MB each, mixable with other source formats
如实说明的限制What it does not do
- 远程图片、样式表与字体在打包前被剥掉:Word 打开文档时不该替你发起网络请求。图片要么以 data URI 内嵌,要么以相对路径原样保留——相对资源不会随包内嵌Remote images, stylesheets and fonts are stripped before packing: Word must not issue a network request while opening your file. Images either arrive as data URIs or stay as relative paths — relative resources are not embedded into the package
- 版式不是逐像素复刻:Word 用自己的 HTML 子集与文档主题渲染,复杂 CSS(绝对定位、浮动、网格、媒体查询)会退化,页边距与字体由 Word 决定Layout is not reproduced pixel for pixel: Word renders the markup through its own HTML subset and document theme, so complex CSS (absolute positioning, floats, grid, media queries) degrades, and margins and fonts come from Word
- 产物依赖 Word 对 altChunk 的支持;少数不处理 altChunk 的阅读器可能显示不出正文,交付前请用目标环境打开确认The result depends on Word supporting altChunk; a reader that does not handle altChunk may show no body text, so open the file in the target environment before delivery
- 脚本与事件处理器在净化时被移除,依赖 JavaScript 才有内容的页面只会剩下静态标记Scripts and event handlers are removed by the sanitizer, so a page whose content only exists after JavaScript keeps just its static markup
实操提示Working with it
- 这条与 Markdown → Word 的取舍得不同:那条先把标记解析成语义化 HTML,这条直接打包你给的 HTML 结构;源里有内联样式时,Word 认得出的那部分会跟着走This differs from Markdown → Word: that route parses markers into semantic HTML first, while this one packs the HTML structure you supply; inline styles survive to the extent Word recognises them
- 同一份 HTML 还能接着转 Markdown、纯文本或 PDF;PDF 那条是整页渲染、没有文字层,与这条正好互补The same HTML can carry on to Markdown, plain text or PDF; the PDF route renders whole pages with no text layer, which complements this one
- 远程资源被剥掉这件事会在产物里如实体现,不会假装图片还在Stripped remote resources are reflected honestly in the result — nothing pretends the images are still there
常见问题Questions people actually ask
Word 打开时会联网吗?Will Word go online when it opens the file?
不会。指向 http(s) 的图片、样式表与字体在打包前就被剥掉,协议相对地址也不例外;文档里只剩内嵌数据与相对路径。链接本身保留,只有你主动点它才会打开浏览器。No. Images, stylesheets and fonts behind http(s) URLs are stripped before packing, protocol-relative addresses included; only embedded data and relative paths remain. Links stay, but only a click of yours opens the browser.
内联 SVG 图会变成什么?What happens to an inline SVG diagram?
在打包前栅格化成 PNG。净化器为移除可执行标记所用的 html 配置里没有 svg 标签,所以顺序必须是“先栅格化、再净化”;否则一张图会在结果里整块消失,而转换仍报成功。It is rasterized to PNG before packing. The sanitizer’s html profile, which exists to remove executable markup, carries no svg tag, so the order has to be rasterize-then-sanitize; otherwise the diagram disappears from the result while the conversion still reports success.
为什么打开后排版和浏览器里不一样?Why does the layout differ from the browser?
因为渲染它的是 Word,不是浏览器。这条路径把结构交给 Word,样式只保留 Word 认得出的那部分;绝对定位、浮动与媒体查询这类浏览器版式没有对应物,页边距与字体也来自 Word 的文档主题。Because Word renders it, not a browser. This route hands the structure to Word and keeps only the styling Word understands; absolute positioning, floats and media queries have no counterpart, and margins and fonts come from Word’s document theme.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。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