agentleFS
Marnie0415Marnie0415/pi-skills/docx-processing/SKILL.md

docx-processing

Skill1 starsChanged 5 months agoMITView on GitHub

Create, read, and modify Microsoft Word (.docx) documents. Use when the user needs to generate reports, extract text, edit Word files, or convert documents to/from .docx format.

  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

DOCX 文档处理 Skill

在 Termux Android 上使用纯 Python 工具处理 .docx 文件。

可用工具

优先方案: python-docx(推荐)

# 安装 (如果尚未安装)
pip install python-docx

备用方案: 解压 + XML 操作

.docx 本质是一个 ZIP 包(XML 内容),可以手动解压处理:

unzip -o file.docx -d docx_unpacked/
# 编辑 docx_unpacked/word/document.xml 等
cd docx_unpacked && zip -r ../modified.docx *

常见操作

1. 创建新的 DOCX 文件

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

doc = Document()
doc.add_heading('标题', level=1)
doc.add_paragraph('正文内容')
doc.save('output.docx')

2. 读取并提取内容

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)

3. 替换占位符(模板替换)

from docx import Document
doc = Document('template.docx')
for para in doc.paragraphs:
    if '{{NAME}}' in para.text:
        para.text = para.text.replace('{{NAME}}', '张三')
doc.save('filled.docx')

4. 添加表格 / 图片

table = doc.add_table(rows=3, cols=3)
table.cell(0, 0).text = '表头1'
doc.add_picture('chart.png', width=Inches(4))

注意事项

  • 📏 用 python-docx 时注意段落/样式 API 的版本差异
  • 📐 表格操作需显式设置列宽
  • 🔄 中文内容确保使用 UTF-8 编码
  • ⚠️ 大文件(>10MB)建议用流式方式处理
  • 💾 处理前先备份原文件

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.