360 Secure SkillHub
360 安全技能中心

Word Handler

该技能基于 python-docx 在本地处理 .docx 文件,可用于新建文档、读取内容、编辑样式、处理表格与页面布局,并提供模板填充思路和一个按 JSON 数据或模板生成报价单文档的命令行脚本。全部处理在本地完成,不调用外部服务。

cjboy007
cjboy007
热度 41.47
最近更新 2026-05-11 17:37:15
分类:效率依赖:代码执行 / 读写文件应用场景:模板 / 报告撰写 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add ssa-word-docx
Metadata
name
Word / DOCX
description
Create, read, and edit Word documents (.docx) with support for templates, tables, and styling.
metadata
{"clawdbot":{"emoji":"📘","os":["linux","darwin","win32"]}}

When to Use

User needs to create, read, or edit Word documents (.docx). Supports template filling, table generation, and professional styling.

Architecture

This skill uses python-docx for DOCX manipulation. All processing happens locally.

Quick Reference

Topic File
Generate Quotation scripts/generate_quotation_docx.py

Core Rules

1. Use Templates for Consistency

When generating documents repeatedly (quotations, proposals), use templates with placeholder text that gets replaced.

2. Handle Chinese Filenames Carefully

Use glob wildcards or pathlib for Chinese filename compatibility:

from pathlib import Path
for f in Path(".").glob("*.docx"):
    doc = Document(str(f))

3. Tables Need Explicit Styling

Word tables require explicit border and cell styling. Use Table Grid style as baseline.

4. Section Properties Control Layout

Page margins, orientation, and headers/footers are controlled at section level:

for section in doc.sections:
    section.left_margin = Cm(2.5)
    section.right_margin = Cm(2.5)

5. Runs vs Paragraphs

Text formatting happens at run level. A paragraph can contain multiple runs with different styles.

Common Traps

  • Merged cells - Only top-left cell holds value in merged ranges
  • Page breaks - Insert explicitly with doc.add_page_break()
  • Images - Require absolute paths or file-like objects
  • Styles - Built-in styles vary by Word version; test compatibility

Dependencies

pip3 install python-docx

Security & Privacy

Data that stays local:

  • All file processing happens locally
  • No external services called

This skill does NOT:

  • Send data to external endpoints
  • Require network access

Related Skills

  • read-docx — Read-only DOCX extraction
  • excel-xlsx — Excel file handling
  • pdf-text-extractor — PDF text extraction

Feedback

  • If useful: clawhub star word-docx
  • Stay updated: clawhub sync