name: word-toolkit description: "Word文件處理工具套件,提供Word文件的建立、讀取、內容提取和基本處理功能。" homepage: https://github.com/wanghao20150901/openclawkit-word.git metadata: { "openclaw": { "emoji": "📝", "requires": { "bins": [], "python": ["python-docx"] } } }
這是一個功能完整的Word文件處理工具套件,提供Word文件的建立、讀取、內容提取和基本處理功能。
✅ 使用此工具當: - 需要自動化生成Word文件 - 需要從Word文件中提取文本內容 - 需要批次處理多個Word文件 - 需要將資料匯出為Word格式 - 需要進行文件格式轉換
python-docx (Word文件處理)安裝依賴:
pip install python-docx
# 檢視幫助
python scripts/main.py --help
# 建立Word文件
python scripts/main.py create --file report.docx --title "專案報告"
# 讀取Word文件
python scripts/main.py read --file document.docx
# 提取文本內容
python scripts/main.py extract --file document.docx --output text.txt
# 批次處理
python scripts/main.py batch --input "*.docx" --output extracted/
from openclawkit_word import WordToolkit
# 初始化工具
word = WordToolkit(debug=True)
# 建立Word文件
content = {
'title': '專案報告',
'paragraphs': [
'這是專案概述。',
'這是詳細說明。',
'這是總結部分。'
],
'tables': [{
'headers': ['任務', '負責人', '進度'],
'rows': [
['需求分析', '張三', '100%'],
['開發實現', '李四', '80%'],
['測試驗收', '王五', '60%']
]
}]
}
word.create_document('專案報告.docx', content)
# 讀取Word文件
doc_content = word.read_document('專案報告.docx')
if doc_content:
print(f"段落數: {len(doc_content['paragraphs'])}")
print(f"表格數: {len(doc_content['tables'])}")
# 提取文本
text = word.extract_text('專案報告.docx')
print(f"提取的文本: {text[:500]}...")
7w4.net提供免費和付費技能下載。
from openclawkit_word import WordToolkit
# 建立工具例項
word = WordToolkit()
# 檢查依賴
if word.check_docx_installed():
# 建立簡單文件
simple_content = {
'title': '會議紀要',
'paragraphs': [
'會議時間:2026年3月28日',
'參會人員:張三、李四、王五',
'會議內容:討論專案進展和下一步計劃'
]
}
if word.create_document('會議紀要.docx', simple_content):
print("✅ 文件建立成功")
# 讀取文件
content = word.read_document('會議紀要.docx')
if content:
for i, paragraph in enumerate(content['paragraphs'], 1):
print(f"段落{i}: {paragraph}")
from openclawkit_word import WordToolkit
import json
word = WordToolkit(debug=True)
# 從JSON資料生成報告
def generate_report_from_json(json_file, output_file):
with open(json_file, 'r', encoding='utf-8') as f:
data = json.load(f)
report_content = {
'title': f"{data['project_name']} - 專案報告",
'paragraphs': [
f"專案名稱: {data['project_name']}",
f"專案負責人: {data['project_manager']}",
f"開始日期: {data['start_date']}",
f"結束日期: {data['end_date']}",
f"專案狀態: {data['status']}",
"",
"專案里程碑:"
],
'tables': []
}
# 添加里程碑表格
if 'milestones' in data:
milestones_table = {
'headers': ['里程碑', '計劃完成', '實際完成', '狀態'],
'rows': []
}
for milestone in data['milestones']:
milestones_table['rows'].append([
milestone['name'],
milestone['planned_date'],
milestone.get('actual_date', '未完成'),
milestone['status']
])
report_content['tables'].append(milestones_table)
# 新增任務表格
if 'tasks' in data:
tasks_table = {
'headers': ['任務', '負責人', '優先順序', '進度'],
'rows': []
}
for task in data['tasks']:
tasks_table['rows'].append([
task['description'],
task['assignee'],
task['priority'],
f"{task['progress']}%"
])
report_content['tables'].append(tasks_table)
# 生成Word文件
if word.create_document(output_file, report_content):
print(f"✅ 報告生成成功: {output_file}")
return True
else:
print(f"❌ 報告生成失敗")
return False
# 使用示例
generate_report_from_json('project_data.json', '專案報告.docx')
工具包含完善的錯誤處理機制: - 檔案損壞或加密處理 - 格式不支援處理 - 記憶體不足處理 - 許可權錯誤處理
MIT License
浩哥 (Hao Ge)
歡迎提交Issue和Pull Request: - GitHub: https://github.com/wanghao20150901/openclawkit-word.git - Email: 512975801@qq.com
這個工具質量不錯,能可靠地建立和讀取Word文件、提取其中的文本內容。文件寫得很清楚,看一遍就能上手使用。程式碼本身比較穩定,沒有明顯問題。但目前功能比較基礎,缺少一些進階能力。另外文件裡有幾處說明與實際使用方式對不上,容易讓人困惑。總體來說適合日常簡單使用,對更復雜的需求支援有限。