docx-tool

使用 python-docx 库创建、读取和修改 Word 文档 (.docx)。支持文本、段落、表格、样式、图片等操作。

3,891 stars

Best use case

docx-tool is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

使用 python-docx 库创建、读取和修改 Word 文档 (.docx)。支持文本、段落、表格、样式、图片等操作。

Teams using docx-tool should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/docx-tool/SKILL.md --create-dirs "https://raw.githubusercontent.com/openclaw/skills/main/skills/adtomato/docx-tool/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/docx-tool/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How docx-tool Compares

Feature / Agentdocx-toolStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

使用 python-docx 库创建、读取和修改 Word 文档 (.docx)。支持文本、段落、表格、样式、图片等操作。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# DOCX 文档操作工具

使用 python-docx 库进行 Word 文档的创建、读取和修改。

## 前置要求

已安装 python-docx:
```bash
pip install python-docx
```

## 常用操作

### 创建新文档

```python
from docx import Document
from docx.shared import Inches, Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH

# 创建新文档
doc = Document()

# 添加标题
doc.add_heading('文档标题', level=1)

# 添加段落
p = doc.add_paragraph('这是一个普通段落。')
p.add_run('这是加粗文字').bold = True
p.add_run(',这是普通文字。')

# 保存文档
doc.save('output.docx')
```

### 读取现有文档

```python
from docx import Document

doc = Document('input.docx')

# 读取所有段落文本
for para in doc.paragraphs:
    print(para.text)

# 读取表格
for table in doc.tables:
    for row in table.rows:
        for cell in row.cells:
            print(cell.text)
```

### 添加表格

```python
from docx import Document

doc = Document()

# 创建 3x3 表格
table = doc.add_table(rows=3, cols=3)
table.style = 'Light Grid Accent 1'

# 填充表头
hdr_cells = table.rows[0].cells
hdr_cells[0].text = '姓名'
hdr_cells[1].text = '年龄'
hdr_cells[2].text = '城市'

# 填充数据
row_cells = table.rows[1].cells
row_cells[0].text = '张三'
row_cells[1].text = '25'
row_cells[2].text = '北京'

doc.save('table.docx')
```

### 设置样式

```python
from docx import Document
from docx.shared import Pt, RGBColor, Inches
from docx.enum.text import WD_ALIGN_PARAGRAPH

doc = Document()

# 添加标题并设置样式
heading = doc.add_heading('标题', level=1)
heading.alignment = WD_ALIGN_PARAGRAPH.CENTER

# 添加段落并设置格式
p = doc.add_paragraph()
run = p.add_run('自定义格式文字')
run.font.size = Pt(14)
run.font.bold = True
run.font.color.rgb = RGBColor(255, 0, 0)

# 设置段落间距
p.paragraph_format.space_before = Pt(12)
p.paragraph_format.space_after = Pt(12)

doc.save('styled.docx')
```

### 添加图片

```python
from docx import Document
from docx.shared import Inches

doc = Document()
doc.add_heading('带图片的文档', level=1)

# 添加图片
doc.add_picture('image.png', width=Inches(5.0))

# 添加图片说明
doc.add_paragraph('图 1: 示例图片', style='Caption')

doc.save('with_image.docx')
```

### 修改现有文档

```python
from docx import Document

doc = Document('existing.docx')

# 在开头插入段落
doc.paragraphs[0].insert_paragraph_before('新插入的段落')

# 修改现有段落
if doc.paragraphs:
    doc.paragraphs[0].text = '修改后的文字'

# 添加新内容到末尾
doc.add_paragraph('添加到末尾的段落')

doc.save('modified.docx')
```

## 可用表格样式

- `Table Grid` - 基础网格
- `Light Grid Accent 1` - 浅色网格
- `Medium Grid 1` - 中等网格
- `Medium Grid 2` - 中等网格 2
- `Medium Grid 3` - 中等网格 3

## 段落对齐方式

- `WD_ALIGN_PARAGRAPH.LEFT` - 左对齐
- `WD_ALIGN_PARAGRAPH.CENTER` - 居中
- `WD_ALIGN_PARAGRAPH.RIGHT` - 右对齐
- `WD_ALIGN_PARAGRAPH.JUSTIFY` - 两端对齐

## 注意事项

1. **文件格式**: 仅支持 .docx 格式,不支持 .doc 格式
2. **兼容性**: 复杂格式在不同 Word 版本间可能有差异
3. **图片**: 支持的格式包括 PNG, JPEG, GIF, BMP
4. **字体**: 使用系统已安装的字体

Related Skills

AI Coding Toolkit — Master Every AI Coding Assistant

3891
from openclaw/skills

> The complete methodology for 10X productivity with AI-assisted development. Covers Cursor, Windsurf, Cline, Aider, Claude Code, GitHub Copilot, and more — tool-agnostic principles that work everywhere.

china-tools-sourcing

3891
from openclaw/skills

Comprehensive tools industry sourcing guide for international buyers – provides detailed information about China's hand tools, power tools, garden tools, measuring tools, and industrial tool manufacturing clusters, supply chain structure, regional specializations, and industry trends (2026 updated).

github-tools

3891
from openclaw/skills

Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.

DevOps & Infrastructure

creator-casting-tool

3891
from openclaw/skills

Find the right creators for any brand campaign, activation, or ambassador program. Takes a campaign brief (brand, vibe, category, budget, audience), searches Instagram, TikTok, YouTube, and Substack, and returns a castable shortlist with stats, content examples, rate estimates, and brand conflict checks. Use when casting creators for campaigns, sourcing influencers for a brand, building ambassador shortlists, finding creators for events/activations, or matching talent to a brief. Triggers on: 'find creators for,' 'cast for this campaign,' 'who should we use for,' 'source influencers,' 'creator shortlist,' 'casting list,' 'find talent for [brand],' 'ambassador search,' or any request to match creators to a brand or campaign brief.

tooldeck

3891
from openclaw/skills

Auto-scrapes URLs to extract tool/service info, auto-categorizes, and saves to a personal database. Use when user explicitly shares a URL to save or asks to remember a service. Always confirm before saving. Never auto-save without user intent.

aaddyy-ai-tools

3891
from openclaw/skills

Access 100+ AI tools via MCP — image generation, article writing, logo creation, SEO analysis, math solving, video generation. One API key, pay-per-use pricing.

chrome-devtools

3891
from openclaw/skills

Uses Chrome DevTools via MCP for efficient debugging, troubleshooting and browser automation. Use when debugging web pages, automating browser interactions, analyzing performance, or inspecting network requests.

office-toolkit

3891
from openclaw/skills

处理 Office 文档(Word/Excel/PPT/PDF)的技能。当用户要求读取、创建、编辑 Word 文档(.docx)、Excel 表格(.xlsx/.csv)、PPT(.pptx)或 PDF 时使用。基于 python-docx、openpyxl、python-pptx、pypdf 库。Requires: python-docx, openpyxl, python-pptx, pypdf, pandoc, LibreOffice(验证用)。

pdf-tool

3891
from openclaw/skills

PDF文字提取工具 — 支持从PDF文件中提取文字内容,用于解析简历。by Barry

devtools-secrets

3891
from openclaw/skills

Knowledge and guardrails for the mise + fnox + infisical secrets toolchain. Use when the user asks to "configure secrets", "set up fnox", "infisical", "mise env", "secrets management", "environment variables for secrets", or mentions secret injection, secret providers, or env var hygiene.

searxng-tool-for-openclaw

3891
from openclaw/skills

Install an OpenClaw plugin that adds SearXNG-powered web search without paid search APIs.

Feishu SuperToolkit

3891
from openclaw/skills

飞书超级工具包 - 集成文件发送(含音频卡片)、日历、审批、多维表格、通讯录、考勤六大模块