支持读取Word文档(.docx/.doc)及中文,可提取文本、搜索关键词并保存为UTF-8文本文件,无需安装Word。
A professional tool for reading Microsoft Word documents, supporting both modern .docx and legacy .doc formats with full Chinese language support.
bash
pip install python-docx olefile
bash
# Copy to your OpenClaw skills directory
cp -r read-word ~/.openclaw/skills/
bash
# Basic reading (shows first 100 paragraphs)
python ~/.openclaw/skills/read-word/read_word.py "document.docx"
# Show more content
python ~/.openclaw/skills/read-word/read_word.py "document.docx" --limit 200
# Search for keywords
python ~/.openclaw/skills/read-word/read_word.py "document.docx" --search "keyword1,keyword2"
# Save as text file
python ~/.openclaw/skills/read-word/read_word.py "document.docx" --output "output.txt"
# Show document info only
python ~/.openclaw/skills/read-word/read_word.py "document.docx" --info
python
# Method 1: Import functions
import sys
sys.path.insert(0, '~/.openclaw/skills/read-word')
from read_word import read_word_document, search_in_document
# Read document
paragraphs = read_word_document("document.docx")
for para in paragraphs:
print(para)
# Search keywords
results = search_in_document("document.docx", ["keyword1", "keyword2"])
python
from read_word import read_word_document
paragraphs = read_word_document("report.docx")
print(f"Document has {len(paragraphs)} paragraphs")
# Show first 10 paragraphs
for i, p in enumerate(paragraphs[:10]):
print(f"{i+1}. {p}")
python
from read_word import search_in_document
# Find paragraphs containing "kitchen" or "feng shui"
results = search_in_document("book.docx", ["kitchen", "feng shui"])
for r in results:
print(r)
python
from pathlib import Path
from read_word import read_word_document
desktop = Path.home() / "Desktop"
for doc_file in desktop.glob("*.docx"):
paragraphs = read_word_document(doc_file)
print(f"{doc_file.name}: {len(paragraphs)} paragraphs")
read_word_document(filepath)#Read a Word document and return a list of paragraphs.
Parameters:
filepath (str|Path): Path to the Word documentReturns:
list: List of paragraph stringsRaises:
FileNotFoundError: If file doesn't existValueError: If file format is not supportedsearch_in_document(filepath, keywords)#Search for keywords in a Word document.
Parameters:
filepath (str|Path): Path to the Word documentkeywords (list): List of keywords to search forReturns:
list: Matching paragraphs with format "[Paragraph N] content"save_as_text(paragraphs, output_path)#Save paragraphs to a UTF-8 text file.
Parameters:
paragraphs (list): List of paragraph stringsoutput_path (str|Path): Output file pathanalyze_document(filepath)#Analyze document and return statistics.
Returns:
dict: Contains filename, size, paragraphs count, total charactersSolution: pip install python-docx
Reason: OLE parsing has limitations with complex formatting Solution: Convert .doc to .docx using Microsoft Word, then read
Reason: Terminal encoding issue
Solution: Use --output to save to file, then open with editor
FormatExtensionSupport LevelWord 2007+.docxFullWord 97-2003.docPartial (text only)Word 95/6.0.docNot supportedRich Text.rtfNot supported
--outputRisk Level: LOW - Local file operations only, no network access, original files are never modified.
叶文洁 (Ye Wenjie) - Created for reading Feng Shui books and Word documents
MIT License