docx-generator by jwynia/agent-skills
npx skills add https://github.com/jwynia/agent-skills --skill docx-generator在以下情况下使用此技能:
{{TITLE}} 或 ${author}在以下情况下不要使用此技能:
{{PLACEHOLDERS}} 替换为实际内容广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
提取文本清单以了解可以替换的内容:
deno run --allow-read scripts/analyze-template.ts corporate-template.docx > inventory.json
输出 (inventory.json):
{
"filename": "corporate-template.docx",
"paragraphCount": 25,
"tableCount": 2,
"imageCount": 1,
"paragraphs": [
{
"index": 0,
"style": "Title",
"fullText": "{{DOCUMENT_TITLE}}",
"runs": [
{ "text": "{{DOCUMENT_TITLE}}", "bold": true, "fontSize": 28 }
]
}
],
"placeholders": [
{ "tag": "{{DOCUMENT_TITLE}}", "location": "paragraph", "paragraphIndex": 0 },
{ "tag": "{{AUTHOR}}", "location": "footer-default", "paragraphIndex": 0 },
{ "tag": "${date}", "location": "table", "tableIndex": 0, "cellLocation": "R1C2" }
]
}
创建 replacements.json:
{
"textReplacements": [
{ "tag": "{{DOCUMENT_TITLE}}", "value": "Q4 2024 Financial Report" },
{ "tag": "{{AUTHOR}}", "value": "Finance Department" },
{ "tag": "${date}", "value": "December 15, 2024" },
{ "tag": "{{COMPANY}}", "value": "Acme Corporation" }
],
"includeHeaders": true,
"includeFooters": true
}
deno run --allow-read --allow-write scripts/generate-from-template.ts \
corporate-template.docx replacements.json output.docx
创建 spec.json:
{
"title": "Quarterly Report",
"creator": "Finance Team",
"styles": {
"defaultFont": "Calibri",
"defaultFontSize": 11
},
"sections": [
{
"header": {
"paragraphs": [
{ "text": "Acme Corporation", "alignment": "right" }
]
},
"footer": {
"paragraphs": [
{ "text": "Confidential", "alignment": "center" }
]
},
"content": [
{
"text": "Q4 2024 Financial Report",
"heading": 1,
"alignment": "center"
},
{
"runs": [
{ "text": "Executive Summary: ", "bold": true },
{ "text": "This report provides an overview of our financial performance for Q4 2024." }
]
},
{ "pageBreak": true },
{
"text": "Revenue Breakdown",
"heading": 2
},
{
"rows": [
{
"cells": [
{ "content": [{ "text": "Category" }], "shading": "DDDDDD" },
{ "content": [{ "text": "Amount" }], "shading": "DDDDDD" },
{ "content": [{ "text": "Change" }], "shading": "DDDDDD" }
],
"isHeader": true
},
{
"cells": [
{ "content": [{ "text": "Product Sales" }] },
{ "content": [{ "text": "$1,250,000" }] },
{ "content": [{ "text": "+15%" }] }
]
},
{
"cells": [
{ "content": [{ "text": "Services" }] },
{ "content": [{ "text": "$750,000" }] },
{ "content": [{ "text": "+8%" }] }
]
}
],
"width": 100,
"borders": true
}
]
}
]
}
deno run --allow-read --allow-write scripts/generate-scratch.ts spec.json output.docx
场景:从品牌模板生成合同。
步骤:
# 1. 分析模板以查找可替换内容
deno run --allow-read scripts/analyze-template.ts contract-template.docx --pretty
# 2. 使用客户数据创建 replacements.json
# 3. 生成合同
deno run --allow-read --allow-write scripts/generate-from-template.ts \
contract-template.docx replacements.json acme-contract.docx
场景:生成包含表格和格式的数据报告。
spec.json:
{
"title": "Sales Report",
"sections": [{
"content": [
{ "text": "Monthly Sales Report", "heading": 1 },
{ "text": "January 2025", "heading": 2 },
{
"runs": [
{ "text": "Total Sales: ", "bold": true },
{ "text": "$125,000", "color": "2E7D32" }
]
}
]
}]
}
场景:创建带有信头的正式信函。
spec.json:
{
"sections": [{
"header": {
"paragraphs": [
{ "text": "ACME CORPORATION", "alignment": "center", "runs": [{"text": "ACME CORPORATION", "bold": true, "fontSize": 16}] },
{ "text": "123 Business Ave, City, ST 12345", "alignment": "center" }
]
},
"content": [
{ "text": "December 15, 2024", "alignment": "right" },
{ "text": "" },
{ "text": "Dear Valued Customer," },
{ "text": "" },
{ "text": "Thank you for your continued business..." },
{ "text": "" },
{ "text": "Sincerely," },
{ "text": "John Smith" },
{ "runs": [{ "text": "CEO", "italic": true }] }
],
"footer": {
"paragraphs": [
{ "text": "www.acme.com | contact@acme.com", "alignment": "center" }
]
}
}]
}
| 脚本 | 用途 | 所需权限 |
|---|---|---|
analyze-template.ts | 从 DOCX 中提取文本、表格、占位符 | --allow-read |
generate-from-template.ts | 替换模板中的占位符 | --allow-read --allow-write |
generate-scratch.ts | 根据 JSON 规范创建 DOCX | --allow-read --allow-write |
| 属性 | 类型 | 描述 |
|---|---|---|
text | string | 简单文本内容 |
runs | array | 格式化文本片段(用于混合格式) |
heading | 1-6 | 标题级别 |
alignment | string | left, center, right, justify |
bullet | boolean | 项目符号列表项 |
numbering | boolean | 编号列表项 |
spacing | object | before, after, line 间距 |
indent | object | left, right, firstLine 缩进 |
pageBreakBefore | boolean | 在段落前插入分页符 |
| 属性 | 类型 | 描述 |
|---|---|---|
text | string | 文本内容 |
bold | boolean | 粗体格式 |
italic | boolean | 斜体格式 |
underline | boolean | 下划线格式 |
strike | boolean | 删除线 |
fontSize | number | 字体大小(磅值) |
font | string | 字体族名称 |
color | string | 文本颜色(十六进制,不带 #) |
highlight | string | 高亮颜色 |
superScript | boolean | 上标 |
subScript | boolean | 下标 |
| 属性 | 类型 | 描述 |
|---|---|---|
rows | array | 行规范数组 |
width | number | 表格宽度百分比 |
borders | boolean | 显示表格边框 |
| 属性 | 类型 | 描述 |
|---|---|---|
text | string | 链接文本 |
url | string | 目标 URL |
bold | boolean | 粗体格式 |
italic | boolean | 斜体格式 |
症状:输出 DOCX 仍包含 {{PLACEHOLDER}} 标签。
解决方案:
analyze-template.ts 以验证确切的标签文本includeHeaders 和 includeFooters 为 true症状:替换后的文本与原始格式不匹配。
解决方案:
症状:输出文档中的图片元素为空白。
解决方案:
症状:表格单元格内容或格式错误。
解决方案:
content 必须是段落规范数组shading 设置背景色,verticalAlign 设置对齐方式每周安装数
291
仓库
GitHub 星标数
37
首次出现
2026年1月20日
安全审计
已安装于
opencode263
codex253
gemini-cli250
cursor241
github-copilot241
amp222
Use this skill when:
{{TITLE}} or ${author}Do NOT use this skill when:
Template Mode : Modify existing branded templates
{{PLACEHOLDERS}} with actual contentScratch Mode : Create documents from nothing using JSON specifications
Extract text inventory to understand what can be replaced:
deno run --allow-read scripts/analyze-template.ts corporate-template.docx > inventory.json
Output (inventory.json):
{
"filename": "corporate-template.docx",
"paragraphCount": 25,
"tableCount": 2,
"imageCount": 1,
"paragraphs": [
{
"index": 0,
"style": "Title",
"fullText": "{{DOCUMENT_TITLE}}",
"runs": [
{ "text": "{{DOCUMENT_TITLE}}", "bold": true, "fontSize": 28 }
]
}
],
"placeholders": [
{ "tag": "{{DOCUMENT_TITLE}}", "location": "paragraph", "paragraphIndex": 0 },
{ "tag": "{{AUTHOR}}", "location": "footer-default", "paragraphIndex": 0 },
{ "tag": "${date}", "location": "table", "tableIndex": 0, "cellLocation": "R1C2" }
]
}
Create replacements.json:
{
"textReplacements": [
{ "tag": "{{DOCUMENT_TITLE}}", "value": "Q4 2024 Financial Report" },
{ "tag": "{{AUTHOR}}", "value": "Finance Department" },
{ "tag": "${date}", "value": "December 15, 2024" },
{ "tag": "{{COMPANY}}", "value": "Acme Corporation" }
],
"includeHeaders": true,
"includeFooters": true
}
deno run --allow-read --allow-write scripts/generate-from-template.ts \
corporate-template.docx replacements.json output.docx
Create spec.json:
{
"title": "Quarterly Report",
"creator": "Finance Team",
"styles": {
"defaultFont": "Calibri",
"defaultFontSize": 11
},
"sections": [
{
"header": {
"paragraphs": [
{ "text": "Acme Corporation", "alignment": "right" }
]
},
"footer": {
"paragraphs": [
{ "text": "Confidential", "alignment": "center" }
]
},
"content": [
{
"text": "Q4 2024 Financial Report",
"heading": 1,
"alignment": "center"
},
{
"runs": [
{ "text": "Executive Summary: ", "bold": true },
{ "text": "This report provides an overview of our financial performance for Q4 2024." }
]
},
{ "pageBreak": true },
{
"text": "Revenue Breakdown",
"heading": 2
},
{
"rows": [
{
"cells": [
{ "content": [{ "text": "Category" }], "shading": "DDDDDD" },
{ "content": [{ "text": "Amount" }], "shading": "DDDDDD" },
{ "content": [{ "text": "Change" }], "shading": "DDDDDD" }
],
"isHeader": true
},
{
"cells": [
{ "content": [{ "text": "Product Sales" }] },
{ "content": [{ "text": "$1,250,000" }] },
{ "content": [{ "text": "+15%" }] }
]
},
{
"cells": [
{ "content": [{ "text": "Services" }] },
{ "content": [{ "text": "$750,000" }] },
{ "content": [{ "text": "+8%" }] }
]
}
],
"width": 100,
"borders": true
}
]
}
]
}
deno run --allow-read --allow-write scripts/generate-scratch.ts spec.json output.docx
Scenario : Generate contracts from a branded template.
Steps :
# 1. Analyze template for replaceable content
deno run --allow-read scripts/analyze-template.ts contract-template.docx --pretty
# 2. Create replacements.json with client data
# 3. Generate contract
deno run --allow-read --allow-write scripts/generate-from-template.ts \
contract-template.docx replacements.json acme-contract.docx
Scenario : Generate a data report with tables and formatting.
spec.json :
{
"title": "Sales Report",
"sections": [{
"content": [
{ "text": "Monthly Sales Report", "heading": 1 },
{ "text": "January 2025", "heading": 2 },
{
"runs": [
{ "text": "Total Sales: ", "bold": true },
{ "text": "$125,000", "color": "2E7D32" }
]
}
]
}]
}
Scenario : Create a formal letter with letterhead.
spec.json :
{
"sections": [{
"header": {
"paragraphs": [
{ "text": "ACME CORPORATION", "alignment": "center", "runs": [{"text": "ACME CORPORATION", "bold": true, "fontSize": 16}] },
{ "text": "123 Business Ave, City, ST 12345", "alignment": "center" }
]
},
"content": [
{ "text": "December 15, 2024", "alignment": "right" },
{ "text": "" },
{ "text": "Dear Valued Customer," },
{ "text": "" },
{ "text": "Thank you for your continued business..." },
{ "text": "" },
{ "text": "Sincerely," },
{ "text": "John Smith" },
{ "runs": [{ "text": "CEO", "italic": true }] }
],
"footer": {
"paragraphs": [
{ "text": "www.acme.com | contact@acme.com", "alignment": "center" }
]
}
}]
}
| Script | Purpose | Permissions |
|---|---|---|
analyze-template.ts | Extract text, tables, placeholders from DOCX | --allow-read |
generate-from-template.ts | Replace placeholders in templates | --allow-read --allow-write |
generate-scratch.ts | Create DOCX from JSON specification | --allow-read --allow-write |
| Property | Type | Description |
|---|---|---|
text | string | Simple text content |
runs | array | Formatted text runs (for mixed formatting) |
heading | 1-6 | Heading level |
alignment | string | left, center, right, |
| Property | Type | Description |
|---|---|---|
text | string | Text content |
bold | boolean | Bold formatting |
italic | boolean | Italic formatting |
underline | boolean | Underline formatting |
strike | boolean | Strikethrough |
| Property | Type | Description |
|---|---|---|
rows | array | Array of row specifications |
width | number | Table width as percentage |
borders | boolean | Show table borders |
| Property | Type | Description |
|---|---|---|
text | string | Link text |
url | string | Target URL |
bold | boolean | Bold formatting |
italic | boolean | Italic formatting |
Symptoms : Output DOCX still contains {{PLACEHOLDER}} tags.
Solution :
analyze-template.ts to verify exact tag textincludeHeaders and includeFooters are true if placeholders are thereSymptoms : Replaced text doesn't match original formatting.
Solution :
Symptoms : Image elements are blank in output.
Solution :
Symptoms : Table cells have wrong content or formatting.
Solution :
content must be an array of paragraph specificationsshading for background color, verticalAlign for alignmentWeekly Installs
291
Repository
GitHub Stars
37
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode263
codex253
gemini-cli250
cursor241
github-copilot241
amp222
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
140,500 周安装
justifybullet | boolean | Bulleted list item |
numbering | boolean | Numbered list item |
spacing | object | before, after, line spacing |
indent | object | left, right, firstLine indentation |
pageBreakBefore | boolean | Insert page break before paragraph |
fontSize |
| number |
| Font size in points |
font | string | Font family name |
color | string | Text color (hex, no #) |
highlight | string | Highlight color |
superScript | boolean | Superscript |
subScript | boolean | Subscript |