| name | read-docx |
| description | Read Word DOCX files and extract text content with proper encoding handling. |
| metadata | {"clawdbot":{"emoji":"📘","os":["linux","darwin","win32"]}} |
Usage
CLI
python3 /path/to/your/.openclaw/workspace/skills/read-docx/read-docx.py "path/*.docx"
python3 read-docx.py "exams/*.docx" --verbose
python3 read-docx.py "exams/HDMI*.docx"
python3 read-docx.py "/path/to/document.docx" -v
Python Code
from docx import Document
import glob
import os
for f in glob.glob("*.docx"):
try:
doc = Document(f)
text = '\n'.join(p.text for p in doc.paragraphs if p.text.strip())
print(f"--- {os.path.basename(f)} ---")
print(text)
except Exception as e:
print(f"Failed to process {f}: {e}")
Why Not read Tool?
- ❌ OpenClaw's
read tool only supports: text files, images (jpg/png/gif/webp)
- ❌ DOCX is a ZIP archive containing XML - needs specialized parsing
- ✅
python-docx handles DOCX structure properly
Important Notes
Chinese Filename Encoding
Chinese filenames may have encoding issues when accessed directly. Always use glob wildcards:
import glob
for f in glob.glob("考试*.docx"):
doc = Document(f)
doc = Document("考试.docx")
Dependencies
pip3 install python-docx
Performance Tips
- Use wildcards - Avoids encoding issues with Chinese filenames
- Generator expression -
'\n'.join(p.text for p in ...) avoids intermediate list
- Filter empty paragraphs -
if p.text.strip() reduces output noise
- For large docs - Extract from runs directly (see code above)
File Structure
read-docx/
├── SKILL.md # This file
├── read-docx.py # CLI script
└── _meta.json # Skill metadata
待补充描述
/path/to/your/.openclaw/workspace/skills/read-docx