离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
CSV 转 Word——离线、值按写下的字符落地、不上传CSV to Word offline — values keep their characters
两步:`csv>html` 用 `XLSX.read(text, { type: "string", raw: true })` 把文件读成一张表,再交给 `sheet_to_html`;`html>docx` 把这份文档交给 `asBlob` 打成一份真的 `.docx` 容器,内容是一段 MHT altChunk——也就是说**排版发生在 Word 里**,字体、列宽、配色都归打开它的那款软件,不归这条链。`raw: true` 是唯一要紧的一步:不加它,SheetJS 的类型推断器会先改写你的数据,实测同一格 `2024-01-05` 在不 raw 的读取下单元格里写的是 `data-t="n" data-v="45296.33383101852"` 而显示文本是 `1/5/24`,加了 raw 之后 `data-v` 与显示文本都是 `2024-01-05` 那一串字符,`00424` 也不会缩成 `424`。还有一条容易被误以为「转换弄丢了东西」的形状要说清:`sheet_to_html` **不产出表头语义**——实测每一行都是 `<tr><td …>`,没有 `<thead>` 也没有 `<th>`,所以第一行在 Word 里与普通行同样处理,想要「标题行」的外观,请在 Word 里勾选表格标题行或自己套样式。安全那条边界也照实说:这段 HTML 不是由我们渲染的,Word 会在用户机器上解析它,所以远程引用在打包前被整体剥掉(`stripRemoteResources`,含 `//host/x.png` 那种协议相对地址),否则一个远程 `<img>` 就变成由另一个应用发出的跟踪像素,落在 CSP 与离线守卫都看不见的地方;内联 SVG 则在净化**之前**先栅格成 PNG,因为 `html` profile 里没有任何 svg 标签——曾经失败过一次「产物是有效的空 .docx 而批次报成功」。打包失败会报 `errors.docxGen`,不会交出一份打不开的文件。全程在这个标签页里完成,只有 storage 权限。Two steps: `csv>html` reads the file with `XLSX.read(text, { type: "string", raw: true })` and hands it to `sheet_to_html`; `html>docx` gives that document to `asBlob`, which packs a real `.docx` container whose body is an MHT altChunk — meaning **the layout happens in Word**: fonts, column widths and colours belong to whatever opens it, not to this chain. `raw: true` is the step that matters. Without it SheetJS’s inferrer rewrites your data first — measured on the same cell, a non-raw read writes `data-t="n" data-v="45296.33383101852"` and displays `1/5/24`, while the raw read writes and displays `2024-01-05`, and `00424` does not shrink to `424`. One shape that is often misread as the converter losing something: `sheet_to_html` **produces no header semantics** — measured, every row is `<tr><td …>` with no `<thead>` and no `<th>`, so the first row is treated like any other in Word; for a title-row look, mark it in Word or apply a style yourself. The security boundary is stated rather than glossed: this markup is not rendered by us — Word parses it on the user’s machine — so remote references are stripped before packing (`stripRemoteResources`, including protocol-relative `//host/x.png`), because otherwise one remote `<img>` becomes a tracking pixel issued by a different application, outside both the CSP and the offline guards. Inline SVG is rasterised to PNG **before** sanitising, since the `html` profile contains no svg tag at all — the earlier failure produced a valid but empty `.docx` while the batch reported success. A packing failure reports `errors.docxGen` instead of handing back a file that will not open. All of it inside this tab on the storage permission.
这条链路怎么走How the route runs
CSVCSV HTMLHTML Word (.docx)Word (.docx)
共 2 步,由扩展的路径搜索自动选出,中间产物不落盘。2 steps, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 值按文件里写下的字符落地:`00424`、`2024-01-05`、`1/2` 都不被推断成数字或日期(实测 `raw: true` 下 `data-v` 与显示文本一致)Values land as the characters the file carries: `00424`, `2024-01-05` and `1/2` are not inferred into numbers or dates (measured: with `raw: true`, `data-v` and the displayed text agree)
- 一个工作表一张表:按 CSV 字节解析就是一张表,产物里不会莫名多出第二张;若正文其实不是 CSV 形状而是 HTML(读取器先看内容再看后缀),多张 `<table>` 会被读成多个工作表,那种情况下每张表前会有一个取自表名的小标题One worksheet, one table: read as CSV bytes there is a single sheet, so no second table appears out of nowhere — and if the payload is really HTML (the reader looks at content before the extension), several tables become several worksheets, each then preceded by a heading carrying its sheet name
- 单元格里的文字内容保留:`sheet_to_html` 写出的是格子里的字,不是重新格式化后的显示串The words inside cells are kept: `sheet_to_html` writes what is in the cell rather than a re-formatted display string
- 远程引用被剥净再交给 Word:这条链不把「打开即发请求」的风险写进产物Remote references are stripped before Word sees the markup, so this chain does not write an open-and-request risk into the artifact
如实说明的限制What it does not do
- 没有表头语义:实测每行都是 `<td>`,既无 `<thead>` 也无 `<th>`,所以 Word 不会知道你的第一行是标题行(要那个外观,请在 Word 里勾「标题行」或自己套样式)No header semantics: measured, every row is `<td>` with no `<thead>` and no `<th>`, so Word is not told your first row is a title — tick “Header Row” there or style it yourself for that look
- 排版不由这条链决定:altChunk 意味着 Word 负责字体、列宽与分页,同一份 CSV 在不同软件里可能排得不一样The layout is not this chain’s decision: an altChunk means Word owns fonts, column widths and pagination, so the same CSV can lay out differently in different software
- 数字类型不迁移:这里不恢复数字与日期类型(那是 CSV→Excel 那条按值取数的路),文档里就是一格一格的字Numeric types do not travel: nothing here restores number or date types (that is what CSV to Excel does with its round-trip typing rule), so the document holds words per cell
- 指向网络或相邻路径的图片取不到字节,且远程引用会被剥掉,所以图不会出现在文档里;文字数据不受影响Images pointed at the network or a sibling path have no bytes and remote references are stripped, so no pictures appear; the text data is unaffected
- 样式与公式不携带:CSV 本身没有格式,条件格式、批注、冻结窗格这些概念在这条链上没有任何对应物Styling and formulas are not carried: a CSV has none, and conditional formatting, comments or frozen panes have no counterpart on this route
实操提示Working with it
- 要可计算的电子表格:CSV→Excel,那条链会把确实是数字的格按「逐字节回得来」的规则还原For a computable spreadsheet: CSV to Excel, whose round-trip rule gives genuine numbers their type back
- 要一份能贴进既有模板的文档:先转 HTML,再由你在 Word 里套样式,比指望这里携带格式更稳For something that must fit an existing template: convert to HTML first, then apply your Word style there — more dependable than expecting styling to travel
- 只是想要一份可读的纯文本表:CSV→TXT / CSV→Markdown,竖线排版在 Markdown 里还能继续编辑For a readable plain-text table: CSV to TXT or Markdown, where the pipe layout stays editable
常见问题Questions people actually ask
第一行是表头,Word 里会显示成表头吗?My first row is a header — will Word show it as one?
不会自动。实测 `sheet_to_html` 每行都写成 `<td>`,没有 `<th>`,所以文档结构里没有「这是标题行」这一项,第一行不会以表头身份存在。要那种外观得由你在打开它的软件里把首行标成标题行——这份产物不替你决定。反过来说,这也意味着任何一行都能被安全地当成数据行处理,不会因为样式而错位。Not automatically. Measured, `sheet_to_html` writes every row as `<td>` with no `<th>`, so the file carries no “this is the title row” information and no row is marked as a header; turning one into a header is your decision in whatever opens it, not this chain’s. The flip side: no row is special, so nothing shifts because of header styling.
为什么我的日期在 Word 里不是日期格式?Why is my date not a date format in Word?
因为这条路刻意不猜类型。CSV 里 `2024-01-05` 只是一串字符,把它「还原成日期」正是把 `1/2` 变成某年某月某日、把邮编 `00424` 变成 `424` 的那一步。所以要的是可计算的日期列,请走 CSV→Excel 那条按值取数的路,而不是让文档替你做这个决定。Because this route deliberately guesses nothing. In a CSV `2024-01-05` is characters, and “restoring” it is exactly the step that turns `1/2` into a calendar day and the zip `00424` into `424`. For real date columns take CSV to Excel with its round-trip rule rather than letting a document make that decision for you.
转换后的 .docx 会被 Word 拦住吗?Will Word block the resulting .docx?
产物是一份 OPC 容器,正文以 altChunk 形式内嵌,排版由打开它的那款软件决定。要说明的是:远程引用在打包前已被剥净,文档里不含需要联网解析的子资源。打包抛错、或返回的不是 Blob 时,界面报转换错误,而不是交出一个未完成的文件。It is an ordinary OPC container whose body is carried as an altChunk, so the layout belongs to whichever application opens it. The point worth stating: remote references are stripped before packing, so the document holds no subresource that would need the network. If packing throws, or hands back something that is not a Blob, the interface reports a conversion error rather than an unfinished file.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。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