Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions external_plugins/docx-mail-merge/.zcode-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "docx-mail-merge",
"version": "0.1.0",
"description": "Fill a Word template’s {{field}} placeholders from a spreadsheet to make one .docx per row — offer letters, contracts, notices, certificates — with all formatting, tables, headers and footers kept. Check missing columns and empty values, fix data in the panel, preview the first document and export the files plus a zip. Runs locally; no API keys.",
"description_i18n": {
"en": "Fill a Word template’s {{field}} placeholders from a spreadsheet to make one .docx per row — offer letters, contracts, notices, certificates — with all formatting, tables, headers and footers kept. Check missing columns and empty values, fix data in the panel, preview the first document and export the files plus a zip. Runs locally; no API keys.",
"zh-CN": "用表格批量填写 Word 模板里的 {{字段}},每行生成一份 .docx(录用通知、合同、通知书、证明等),格式、表格、页眉页脚原样保留。检查缺少的列和空值,在面板里改数据、预览第一份文档,导出全部文件和 zip 压缩包。在本地运行,无需 API 密钥。"
},
"author": {
"name": "Penova",
"url": "https://github.com/ppppp2005-p"
},
"license": "MIT",
"keywords": [
"mail merge",
"docx",
"word",
"template",
"batch",
"letters",
"contracts",
"套打",
"批量生成",
"word 模板",
"邮件合并",
"录用通知",
"合同"
],
"skills": "skills",
"mcpServers": {
"docx-mail-merge": {
"type": "stdio",
"command": "node",
"args": [
"${ZCODE_PLUGIN_ROOT}/dist/server.mjs"
],
"cwd": "${ZCODE_PROJECT_DIR}",
"timeoutMs": 900000,
"env": {
"ZCODE_WORKSPACE_ROOT": "${ZCODE_PROJECT_DIR}"
}
}
},
"ui": {
"surfaces": [
{
"id": "editor",
"title": {
"zh-CN": "Word 批量套打",
"en-US": "DOCX Mail Merge"
},
"icon": "file-text",
"server": "docx-mail-merge",
"resourceUri": "ui://docx-mail-merge/panel.html",
"availability": "session"
}
]
}
}
21 changes: 21 additions & 0 deletions external_plugins/docx-mail-merge/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Penova

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions external_plugins/docx-mail-merge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# DOCX Mail Merge

Fill a Word template’s {{field}} placeholders from a spreadsheet to make one .docx per row — offer letters, contracts, notices, certificates — with all formatting, tables, headers and footers kept. Check missing columns and empty values, fix data in the panel, preview the first document and export the files plus a zip. Runs locally; no API keys.

## Features

- **Template**: type placeholders like `{{Name}}` or `{{姓名}}` anywhere in a Word document — body text, tables, headers, footers, footnotes. Placeholders that Word split across differently formatted runs are still found, and the replaced text keeps the formatting of the placeholder’s first character.
- **Data**: .xlsx or .csv; column names must match the field names. Multi-line values become line breaks.
- **Checks**: fields with no matching column (blocks export), columns the template does not use, rows with empty values, and repeated file names.
- **File names**: a pattern such as `{姓名}-录用通知书` or `{n}` for the row number.
- **Output**: one .docx per row, an optional zip of all documents, and a CSV log listing empty fields per file.
- **Panel**: pick input files, adjust settings, see problems, edit any cell in the table, preview the result and export — all in the ZCode side panel. Edits are saved in `docx-mail-merge/<project>.project.json` and kept until you re-open the inputs.

## Usage

Ask the agent in ZCode Desktop:

- "Use 人事/offer-template.docx and 人事/new-hires.xlsx to make one offer letter per person, named after the person"
- "Alex Turner reports to 王磊 — fill that in"
- "Generate the Word files and a zip"

## Tools

| Tool | Purpose |
|---|---|
| `merge_open` | Read the template’s placeholders and the sheet rows. Opens the panel |
| `merge_edit` | Change settings, edit cells by row, add or remove rows |
| `merge_status` | Show the current rows, issues and summary |
| `merge_export` | Write documents/<name>.docx for every row, all-documents.zip and merge-log.csv |

Output goes to `docx-mail-merge/<project>/` in the workspace.

## Scope (v0.1)

- Plain text replacement only: no conditional sections, repeating table rows, images or Word MERGEFIELD fields in v0.1.
- Output is DOCX (convert to PDF in Word or WPS if needed). Old .doc templates: save as .docx first.
- Nothing is emailed.

## Privacy, network and files

- **Everything runs locally.** No network, no uploads, no API keys or accounts.
- Reads only the files you choose. Writes only the `docx-mail-merge/` folder in the workspace. No hooks.

## Build and test (developers)

- Source: `ui-plugins/docx-mail-merge/`.
- Build: `pnpm install --frozen-lockfile && pnpm build`, then add `dist/local-marketplace` as a local source.
- Tests: `pnpm --filter @penova/plugin-docx-mail-merge test` and `test:e2e` (needs Chrome; sample files in `test/samples/`).

## Third-party components and licenses

MIT licensed (author: Penova). Bundled: fflate (MIT), ExcelJS (MIT), MCP SDK and ext-apps (MIT), zod (MIT); the full list is in `dist/THIRD_PARTY_NOTICES.txt`.
52 changes: 52 additions & 0 deletions external_plugins/docx-mail-merge/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Word 批量套打

用表格批量填写 Word 模板里的 {{字段}},每行生成一份 .docx(录用通知、合同、通知书、证明等),格式、表格、页眉页脚原样保留。检查缺少的列和空值,在面板里改数据、预览第一份文档,导出全部文件和 zip 压缩包。在本地运行,无需 API 密钥。

## 功能

- **模板**:在 Word 里任意位置输入 `{{姓名}}` 这样的占位符——正文、表格、页眉页脚、脚注都可以。即使 Word 把一个占位符拆进了不同格式的几段文字也能识别,替换后的文字沿用占位符第一个字的格式。
- **数据**:.xlsx 或 .csv,列名要和字段名一致。多行内容会变成换行。
- **检查**:模板字段在表格里找不到对应列(会阻止导出)、表格里没用到的列、有空值的行、重复的文件名。
- **文件名**:用 `{姓名}-录用通知书` 这样的规则,`{n}` 是序号。
- **输出**:每行一份 .docx,可选把全部文件打成 zip,另附 CSV 记录每份文件的空字段。
- **面板**:在 ZCode 侧栏里选择输入文件、调整设置、查看问题、直接修改表格里的任意单元格、预览成品并导出。修改保存在 `docx-mail-merge/<项目>.project.json`,重新打开输入文件前一直保留。

## 使用方法

在 ZCode 桌面端对助手说:

- “用 人事/offer-template.docx 和 人事/new-hires.xlsx 给每个人生成一份录用通知书,文件名用姓名”
- “Alex Turner 的上级填王磊”
- “生成 Word 文件并打包成 zip”

## 工具

| 工具 | 作用 |
|---|---|
| `merge_open` | 读取模板里的占位符和表格数据,并打开面板 |
| `merge_edit` | 修改设置、按行修改单元格、新增或删除行 |
| `merge_status` | 查看当前数据、问题和汇总 |
| `merge_export` | 为每行生成 documents/<文件名>.docx,并导出 all-documents.zip 和 merge-log.csv |

导出文件写到工作区的 `docx-mail-merge/<项目>/` 文件夹。

## 范围(v0.1)

- v0.1 只做文字替换:不支持条件段落、重复表格行、图片或 Word 自带的邮件合并域(MERGEFIELD)。
- 输出为 DOCX(需要 PDF 可在 Word 或 WPS 里另存)。旧的 .doc 模板请先另存为 .docx。
- 不会发送邮件。

## 隐私、网络与文件

- **全部在本地运行。** 不联网、不上传,不需要 API 密钥或账号。
- 只读取你选择的文件,只写入工作区的 `docx-mail-merge/` 文件夹。没有 Hook。

## 构建与测试(开发者)

- 源码:`ui-plugins/docx-mail-merge/`。
- 构建:`pnpm install --frozen-lockfile && pnpm build`,然后把 `dist/local-marketplace` 添加为本地来源。
- 测试:`pnpm --filter @penova/plugin-docx-mail-merge test` 和 `test:e2e`(需要 Chrome;样例文件在 `test/samples/`)。

## 第三方组件与许可证

MIT 许可(作者:Penova)。打包的组件:fflate (MIT), ExcelJS (MIT)、MCP SDK 与 ext-apps(MIT)、zod(MIT);完整列表见 `dist/THIRD_PARTY_NOTICES.txt`。
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: docx-mail-merge
description: 用表格批量填写 Word 模板里的 {{字段}},每行生成一份 .docx(录用通知、合同、通知书、证明等),格式、表格、页眉页脚原样保留。检查缺少的列和空值,在面板里改数据、预览第一份文档,导出全部文件和 zip 压缩包。在本地运行,无需 API 密钥。 用户提到“批量生成 Word / 套打 / 邮件合并 / mail merge / 每个人一份通知书或合同”时使用。
---

# Word 批量套打

1. `merge_open(inputs, settings?, project?)`:读取模板里的占位符和表格数据。inputs 是工作区相对路径。
- 结果里有汇总、问题列表(错误 / 提醒)和前几行数据,每行有编号 `#n`。
- inputs 传两个文件:.docx 模板和 .xlsx/.csv 数据表。fileName 设置成用户想要的文件名规则。
- 模板里没有 {{字段}} 时,告诉用户在 Word 里怎么写占位符。
2. 向用户简要说明结果,先说错误和需要确认的地方,不要逐行念。
3. 用户要改时调用 `merge_edit(project, settings?, set?: [{row, values}], add?, remove?)`。
- 改数据:`set: [{row, values: {列名: 值}}]`。字段和列名对不上时,建议用户改表头或改模板里的占位符。
4. `merge_export(project, formats?)`:为每行生成 documents/<文件名>.docx,并导出 all-documents.zip 和 merge-log.csv。把文件路径告诉用户。
51 changes: 51 additions & 0 deletions marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,57 @@
"把上一个 Hi3D 任务生成的模型按角色拆分成部件"
]
}
},
{
"name": "docx-mail-merge",
"componentTypes": [
"ui"
],
"source": "./external_plugins/docx-mail-merge",
"displayName": "DOCX Mail Merge",
"displayName_i18n": {
"en": "DOCX Mail Merge",
"zh-CN": "Word 批量套打"
},
"description": "Fill a Word template’s {{field}} placeholders from a spreadsheet to make one .docx per row — offer letters, contracts, notices, certificates — with all formatting, tables, headers and footers kept. Check missing columns and empty values, fix data in the panel, preview the first document and export the files plus a zip. Runs locally; no API keys.",
"description_i18n": {
"en": "Fill a Word template’s {{field}} placeholders from a spreadsheet to make one .docx per row — offer letters, contracts, notices, certificates — with all formatting, tables, headers and footers kept. Check missing columns and empty values, fix data in the panel, preview the first document and export the files plus a zip. Runs locally; no API keys.",
"zh-CN": "用表格批量填写 Word 模板里的 {{字段}},每行生成一份 .docx(录用通知、合同、通知书、证明等),格式、表格、页眉页脚原样保留。检查缺少的列和空值,在面板里改数据、预览第一份文档,导出全部文件和 zip 压缩包。在本地运行,无需 API 密钥。"
},
"version": "0.1.0",
"author": {
"name": "Penova",
"url": "https://github.com/ppppp2005-p"
},
"license": "MIT",
"category": "productivity",
"keywords": [
"mail merge",
"docx",
"word",
"template",
"batch",
"letters",
"contracts",
"套打",
"批量生成",
"word 模板",
"邮件合并",
"录用通知",
"合同"
],
"examplePrompts": [
"Use 人事/offer-template.docx and 人事/new-hires.xlsx to make one offer letter per person, named after the person",
"Alex Turner reports to 王磊 — fill that in",
"Generate the Word files and a zip"
],
"examplePrompts_i18n": {
"zh-CN": [
"用 人事/offer-template.docx 和 人事/new-hires.xlsx 给每个人生成一份录用通知书,文件名用姓名",
"Alex Turner 的上级填王磊",
"生成 Word 文件并打包成 zip"
]
}
}
]
}
Loading