WORD,OFFICE,office,word文件處理工具

👤 wanghao20150901 📦 v1.0.1 ⭐ 4.1 ⬇️ 958 下載
📄 辦公效率 免費

📖 技能介紹


name: word-toolkit description: "Word文件處理工具套件,提供Word文件的建立、讀取、內容提取和基本處理功能。" homepage: https://github.com/wanghao20150901/openclawkit-word.git metadata: { "openclaw": { "emoji": "📝", "requires": { "bins": [], "python": ["python-docx"] } } }


Word工具套件 (Word Toolkit)

功能概述

這是一個功能完整的Word文件處理工具套件,提供Word文件的建立、讀取、內容提取和基本處理功能。

核心功能

  • 📝 文件建立:建立新的Word文件,支援標題、段落、表格
  • 📖 文件讀取:讀取現有Word文件,提取文本和結構資訊
  • 🔍 內容提取:提取純文本、段落、表格內容
  • 🛠️ 格式處理:基本文件格式處理
  • 📊 批次處理:支援批次文件操作

使用時機

使用此工具當: - 需要自動化生成Word文件 - 需要從Word文件中提取文本內容 - 需要批次處理多個Word文件 - 需要將資料匯出為Word格式 - 需要進行文件格式轉換

環境要求

  • Python 3.6+
  • 依賴包:
  • 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/

Python API使用

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]}...")

功能模組

1. 文件建立模組

  • 建立新文件
  • 新增標題和段落
  • 插入表格
  • 設定基本格式

2. 文件讀取模組

  • 讀取現有文件
  • 提取文件結構
  • 獲取後設資料
  • 驗證文件完整性

3. 內容提取模組

  • 提取純文本
  • 分離段落和表格
  • 保留基本格式
  • 處理特殊字元

4. 格式處理模組

  • 字型和段落格式
  • 表格樣式設定
  • 頁面佈局調整
  • 樣式模板應用

5. 批次處理模組

  • 多文件並行處理
  • 進度跟蹤
  • 結果彙總
  • 錯誤處理

    小蔥技能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')

錯誤處理

工具包含完善的錯誤處理機制: - 檔案損壞或加密處理 - 格式不支援處理 - 記憶體不足處理 - 許可權錯誤處理

效能最佳化

  • 流式處理:支援大文件分批處理
  • 記憶體最佳化:減少記憶體佔用
  • 並行處理:多文件並行操作
  • 快取機制:減少重複讀取

更新日誌

v1.0.1 (2026-03-28)

  • 初始版本釋出
  • 基礎文件建立功能
  • 文件讀取和內容提取
  • 表格處理功能
  • 批次處理支援

許可證

MIT License

作者

浩哥 (Hao Ge)

反饋與貢獻

歡迎提交Issue和Pull Request: - GitHub: https://github.com/wanghao20150901/openclawkit-word.git - Email: 512975801@qq.com

🤖 AI 評測

這個工具質量不錯,能可靠地建立和讀取Word文件、提取其中的文本內容。文件寫得很清楚,看一遍就能上手使用。程式碼本身比較穩定,沒有明顯問題。但目前功能比較基礎,缺少一些進階能力。另外文件裡有幾處說明與實際使用方式對不上,容易讓人困惑。總體來說適合日常簡單使用,對更復雜的需求支援有限。

📊 多維度評分

適應性3.7
規範性3.9
有效性4.1
可靠性4
可信度5

📁 包含檔案 (3 個)

📄 SKILL.md 6.6 KB
📄 _meta.json 135 B
📄 scripts/openclawkit_word.py 8 KB