document-docx by vasilyu1983/ai-agents-public
npx skills add https://github.com/vasilyu1983/ai-agents-public --skill document-docx此技能支持为报告、合同、提案、文档和模板驱动输出创建、编辑和分析 .docx 文件。
现代最佳实践(2026年):
.docx 视为可编辑的源文件;将 PDF 视为发布产物。| 任务 | 工具/库 | 语言 | 使用场景 |
|---|---|---|---|
| 创建 DOCX | python-docx | Python | 报告、合同、提案 |
| 创建 DOCX | docx | Node.js | 服务器端文档生成 |
| 转换为 HTML | mammoth.js | Node.js | 网页显示、内容提取 |
| 解析 DOCX | python-docx |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| Python |
| 提取文本、表格、元数据 |
| 模板填充 | docxtpl | Python | 邮件合并、基于模板的生成 |
| 审阅工作流 | Word 比较、批注/高亮 | 任何 | 无需进行 OOXML 手术的人工审阅 |
| 修订跟踪 | OOXML 检查、docx4j/OpenXML SDK/Aspose | 任何 | 真正的修订标记或解析修订跟踪 |
docxtpl。python-docx。docx (Node.js)。mammoth。.doc(旧版格式);请先转换为 .docx(例如使用 LibreOffice)。python-docx 无法可靠地创建真正的修订跟踪;请使用 Word 比较或专门的 OOXML 工具。from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
doc = Document()
# 标题
title = doc.add_heading('Document Title', 0)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
# 带格式的段落
para = doc.add_paragraph()
run = para.add_run('Bold and ')
run.bold = True
run = para.add_run('italic text.')
run.italic = True
# 表格
table = doc.add_table(rows=3, cols=3)
table.style = 'Table Grid'
for i, row in enumerate(table.rows):
for j, cell in enumerate(row.cells):
cell.text = f'Row {i+1}, Col {j+1}'
# 图片
doc.add_picture('image.png', width=Inches(4))
# 保存
doc.save('output.docx')
import { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell } from 'docx';
import * as fs from 'fs';
const doc = new Document({
sections: [{
properties: {},
children: [
new Paragraph({
children: [
new TextRun({ text: 'Bold text', bold: true }),
new TextRun({ text: ' and normal text.' }),
],
}),
new Table({
rows: [
new TableRow({
children: [
new TableCell({ children: [new Paragraph('Cell 1')] }),
new TableCell({ children: [new Paragraph('Cell 2')] }),
],
}),
],
}),
],
}],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync('output.docx', buffer);
});
from docxtpl import DocxTemplate
doc = DocxTemplate('template.docx')
context = {
'company_name': 'Acme Corp',
'date': '2025-01-15',
'items': [
{'name': 'Widget A', 'price': 100},
{'name': 'Widget B', 'price': 200},
]
}
doc.render(context)
doc.save('filled_template.docx')
from docx import Document
doc = Document('input.docx')
# 提取所有文本
full_text = []
for para in doc.paragraphs:
full_text.append(para.text)
# 提取表格
for table in doc.tables:
for row in table.rows:
row_data = [cell.text for cell in row.cells]
print(row_data)
| 元素 | Python 方法 | Node.js 类 |
|---|---|---|
| 标题 1 | add_heading(text, 1) | HeadingLevel.HEADING_1 |
| 加粗 | run.bold = True | TextRun({ bold: true }) |
| 斜体 | run.italic = True | TextRun({ italics: true }) |
| 字体大小 | run.font.size = Pt(12) | TextRun({ size: 24 }) (半磅) |
| 对齐方式 | WD_ALIGN_PARAGRAPH.CENTER | AlignmentType.CENTER |
| 分页符 | doc.add_page_break() | new PageBreak() |
assets/doc-template-pack.md 获取决策日志和重复文档类型的模板。仅在明确请求且符合政策时使用。
资源
脚本
scripts/docx_inspect_ooxml.py - 无依赖的 OOXML 检查(包括修订跟踪信号)scripts/docx_extract.py - 将文本/表格提取为 JSON(需要 python-docx)scripts/docx_render_template.py - 渲染 docxtpl 模板(需要 docxtpl)scripts/docx_to_html.mjs - 将 .docx 转换为 HTML(需要 mammoth)模板
相关技能
每周安装数
147
代码仓库
GitHub 星标数
46
首次出现
Jan 23, 2026
安全审计
安装于
opencode126
gemini-cli121
cursor120
codex117
github-copilot112
amp104
This skill enables creation, editing, and analysis of .docx files for reports, contracts, proposals, documentation, and template-driven outputs.
Modern best practices (2026):
.docx as the editable source; treat PDF as a release artifact.| Task | Tool/Library | Language | When to Use |
|---|---|---|---|
| Create DOCX | python-docx | Python | Reports, contracts, proposals |
| Create DOCX | docx | Node.js | Server-side document generation |
| Convert to HTML | mammoth.js | Node.js | Web display, content extraction |
| Parse DOCX | python-docx | Python | Extract text, tables, metadata |
| Template fill | docxtpl | Python | Mail merge, template-based generation |
| Review workflow | Word compare, comments/highlights | Any | Human review without OOXML surgery |
| Tracked changes | OOXML inspection, docx4j/OpenXML SDK/Aspose | Any | True redlines or parsing tracked changes |
docxtpl when non-developers must edit layout/design in Word.python-docx for structural edits (paragraphs/tables/headers/footers) when formatting complexity is moderate.docx (Node.js) for server-side generation in TypeScript-heavy stacks.mammoth for text-first extraction or DOCX-to-HTML (best effort; may drop some layout fidelity)..doc (legacy) is not supported by these libraries; convert to .docx first (e.g., LibreOffice).python-docx cannot reliably create true tracked changes; use Word compare or specialized OOXML tooling.from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
doc = Document()
# Title
title = doc.add_heading('Document Title', 0)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
# Paragraph with formatting
para = doc.add_paragraph()
run = para.add_run('Bold and ')
run.bold = True
run = para.add_run('italic text.')
run.italic = True
# Table
table = doc.add_table(rows=3, cols=3)
table.style = 'Table Grid'
for i, row in enumerate(table.rows):
for j, cell in enumerate(row.cells):
cell.text = f'Row {i+1}, Col {j+1}'
# Image
doc.add_picture('image.png', width=Inches(4))
# Save
doc.save('output.docx')
import { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell } from 'docx';
import * as fs from 'fs';
const doc = new Document({
sections: [{
properties: {},
children: [
new Paragraph({
children: [
new TextRun({ text: 'Bold text', bold: true }),
new TextRun({ text: ' and normal text.' }),
],
}),
new Table({
rows: [
new TableRow({
children: [
new TableCell({ children: [new Paragraph('Cell 1')] }),
new TableCell({ children: [new Paragraph('Cell 2')] }),
],
}),
],
}),
],
}],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync('output.docx', buffer);
});
from docxtpl import DocxTemplate
doc = DocxTemplate('template.docx')
context = {
'company_name': 'Acme Corp',
'date': '2025-01-15',
'items': [
{'name': 'Widget A', 'price': 100},
{'name': 'Widget B', 'price': 200},
]
}
doc.render(context)
doc.save('filled_template.docx')
from docx import Document
doc = Document('input.docx')
# Extract all text
full_text = []
for para in doc.paragraphs:
full_text.append(para.text)
# Extract tables
for table in doc.tables:
for row in table.rows:
row_data = [cell.text for cell in row.cells]
print(row_data)
| Element | Python Method | Node.js Class |
|---|---|---|
| Heading 1 | add_heading(text, 1) | HeadingLevel.HEADING_1 |
| Bold | run.bold = True | TextRun({ bold: true }) |
| Italic | run.italic = True | TextRun({ italics: true }) |
| Font size |
assets/doc-template-pack.md for decision logs and recurring doc types.Use only when explicitly requested and policy-compliant.
Resources
Scripts
scripts/docx_inspect_ooxml.py - Dependency-free OOXML inspection (including tracked changes signals)scripts/docx_extract.py - Extract text/tables to JSON (requires python-docx)scripts/docx_render_template.py - Render a docxtpl template (requires docxtpl)scripts/docx_to_html.mjs - Convert .docx to HTML (requires mammoth)Templates
Related Skills
Weekly Installs
147
Repository
GitHub Stars
46
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode126
gemini-cli121
cursor120
codex117
github-copilot112
amp104
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
33,600 周安装
Needle自动化工具包:通过Rube MCP实现Needle操作自动化
1 周安装
Hummingbot幻灯片生成器:从Markdown创建品牌风格PDF演示文稿,支持Mermaid图表
145 周安装
MX Toolbox自动化技能 - 集成Claude AI与MX记录查询工具,提升网络管理效率
1 周安装
Mural自动化技能 - 通过ComposioHQ集成Claude AI实现自动化工作流
1 周安装
Missive自动化工具:通过Rube MCP和Composio实现邮件协作自动化
1 周安装
Microsoft Clarity自动化工具包:通过Rube MCP实现用户行为分析自动化
1 周安装
run.font.size = Pt(12)TextRun({ size: 24 }) (half-points) |
| Alignment | WD_ALIGN_PARAGRAPH.CENTER | AlignmentType.CENTER |
| Page break | doc.add_page_break() | new PageBreak() |