← Back to Skills Marketplace
adtomato

Docx Tool

by xiaodouzi · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
101
Downloads
0
Stars
1
Active Installs
1
Versions
Install in OpenClaw
/install docx-tool
Description
使用 python-docx 库创建、读取和修改 Word 文档 (.docx)。支持文本、段落、表格、样式、图片等操作。
README (SKILL.md)

DOCX 文档操作工具

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

前置要求

已安装 python-docx:

pip install python-docx

常用操作

创建新文档

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')

读取现有文档

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)

添加表格

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')

设置样式

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')

添加图片

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')

修改现有文档

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. 字体: 使用系统已安装的字体
Usage Guidance
This skill is basically a how-to document for python-docx and appears coherent. Before using it: 1) ensure you install python-docx from a trusted source (pip from PyPI) in a controlled environment; 2) be aware the examples read and write local .docx files—do not run the examples against sensitive documents you do not want the agent or execution environment to access; 3) because this is instruction-only, the skill itself doesn’t execute code on install—code will run only if you or an agent actually executes the provided Python snippets. If you plan to let an autonomous agent run these examples, restrict its workspace and review any files it will access.
Capability Analysis
Type: OpenClaw Skill Name: docx-tool Version: 1.0.0 The skill bundle provides standard documentation and code examples for using the legitimate 'python-docx' library to create, read, and modify Word documents. All code snippets in SKILL.md are typical library usage patterns for document manipulation, and there are no indicators of malicious intent, data exfiltration, or prompt injection.
Capability Assessment
Purpose & Capability
Name/description match the SKILL.md examples: all instructions show how to use python-docx to create/read/modify .docx files. There are no unrelated binaries, credentials, or config paths requested.
Instruction Scope
Instructions stay within the stated purpose (file creation, reading, tables, styles, images). They do reference reading and writing local filenames (e.g., 'input.docx', 'existing.docx', 'output.docx') and recommend installing python-docx via pip; this is expected for a docx utility but means the agent or user running these examples will access workspace files—be cautious about sensitive documents.
Install Mechanism
No install spec is included in the skill bundle (instruction-only). The SKILL.md suggests 'pip install python-docx' but the skill does not automatically download or execute anything itself, which is low-risk. Users should install packages from trusted package indexes when running examples.
Credentials
The skill requests no environment variables, credentials, or config paths. That is proportionate to its stated functionality.
Persistence & Privilege
always is false and the skill does not request persistent or elevated platform privileges. It does not modify other skills or system settings.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install docx-tool
  3. After installation, invoke the skill by name or use /docx-tool
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
- Initial release of docx-tool. - Provides examples for creating, reading, and modifying Word (.docx) documents using python-docx. - Includes guides for working with text, paragraphs, tables, styles, and images. - Lists available table styles and paragraph alignment options. - Notes on file format support, compatibility, supported image types, and font usage.
Metadata
Slug docx-tool
Version 1.0.0
License MIT-0
All-time Installs 1
Active Installs 1
Total Versions 1
Frequently Asked Questions

What is Docx Tool?

使用 python-docx 库创建、读取和修改 Word 文档 (.docx)。支持文本、段落、表格、样式、图片等操作。 It is an AI Agent Skill for Claude Code / OpenClaw, with 101 downloads so far.

How do I install Docx Tool?

Run "/install docx-tool" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Docx Tool free?

Yes, Docx Tool is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Docx Tool support?

Docx Tool is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Docx Tool?

It is built and maintained by xiaodouzi (@adtomato); the current version is v1.0.0.

💬 Comments