当前位置: 首页 > Skill >

Read Microsoft Word documents (.docx and .doc) with Chinese support

Read Microsoft Word documents (.docx and .doc) with Chinese support

Read Microsoft Word documents (.docx and .doc) with Chinese support

支持读取Word文档(.docx/.doc)及中文,可提取文本、搜索关键词并保存为UTF-8文本文件,无需安装Word。

1.0.0 2026.11.11 457
获取Skill文件查看使用说明
作 者:许言 许可证: 更新时间:2026.11.11
本文目录展开

Read Word Document

A professional tool for reading Microsoft Word documents, supporting both modern .docx and legacy .doc formats with full Chinese language support.

Features

  • Read .docx files - Word 2007 and later format
  • Read .doc files - Word 97-2003 format via OLE parsing
  • Auto format detection - Automatically identifies file type
  • Full Chinese support - Handles Chinese encoding correctly
  • Keyword search - Search for keywords across all paragraphs
  • Export to text - Save as UTF-8 text files
  • Document analysis - Get document statistics and info
  • No Word required - Works without Microsoft Word installation

Installation

Prerequisites

pip install python-docx olefile

Install Skill

# Copy to your OpenClaw skills directory
cp -r read-word ~/.openclaw/skills/

Usage

Command Line

# 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 API

# 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"])

Examples

Example 1: Read and Analyze

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

Example 2: Search Keywords

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)

Example 3: Batch Processing

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")

API Reference

read_word_document(filepath)

Read a Word document and return a list of paragraphs.

Parameters:

  • filepath (str|Path): Path to the Word document

Returns:

  • list: List of paragraph strings

Raises:

  • FileNotFoundError: If file doesn't exist
  • ValueError: If file format is not supported

search_in_document(filepath, keywords)

Search for keywords in a Word document.

Parameters:

  • filepath (str|Path): Path to the Word document
  • keywords (list): List of keywords to search for

Returns:

  • 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 strings
  • output_path (str|Path): Output file path

analyze_document(filepath)

Analyze document and return statistics.

Returns:

  • dict: Contains filename, size, paragraphs count, total characters

Troubleshooting

Error: ModuleNotFoundError: No module named 'docx'

Solution: pip install python-docx

Error: Legacy .doc file shows garbled text

Reason: OLE parsing has limitations with complex formatting Solution: Convert .doc to .docx using Microsoft Word, then read

Error: Chinese characters display incorrectly

Reason: Terminal encoding issue Solution: Use --output to save to file, then open with editor

File Support

Format Extension Support Level
Word 2007+ .docx Full
Word 97-2003 .doc Partial (text only)
Word 95/6.0 .doc Not supported
Rich Text .rtf Not supported

Permissions

  • Read: User-specified Word documents
  • Write (optional): Output .txt files when using --output
  • Network: None

Security

Risk Level: LOW - Local file operations only, no network access, original files are never modified.

Changelog

v1.0.0 (2026-03-20)

  • Initial release
  • Support .docx and .doc formats
  • Keyword search functionality
  • Text export capability
  • Chinese encoding support

Author

叶文洁 (Ye Wenjie) - Created for reading Feng Shui books and Word documents

License

MIT License

相关文章

更多
document.execCommand() 命令详解与使用限制

document.execCommand 是用于在文档中执行编辑命令的 JavaScript 方法,支持复制、粘贴、格式化等丰富文本操作。该方法在 Firefox 等现代浏览器中支持度较差,许多命令如 BlockDirLTR、JustifyFull 等尚未支持。常用命令包括 Bold、Italic、CreateLink、Copy、Cut、Paste 等,可控制字体、颜色、对齐及插入图片链接等元素。使用时需注意浏览器兼容性差异,部分功能仅在 IE 或旧版浏览器中有效。

2026.01.11 950
基于DOCX模板的动态数据填充:PHP实现Word文档批量生成

使用 PhpOffice\PhpWord 库,通过读取 DOCX 模板中的占位符(如 {{name}} ),利用 setValue() 方法直接替换内容并导出为新的 Word 文档。

2025.04.15 883
document.execCommand 命令参数详解

document.execCommand 方法通过不同的 command 参数控制文档的编辑行为。该 API 支持多种格式化操作,如 Bold、Italic 和 Underline 切换样式,以及 Copy、Cut、Paste 等剪贴板管理功能。此外,它还允许插入链接、书签、图像及各类表单控件,并处理对齐、缩进和列表格式。部分高级或特定于旧版浏览器的功能目前尚未得到支持。

2026.03.27 713
C# 中使用iTextSharp组件创建PDF的简单方法

本文介绍在C#项目中利用iTextSharp库生成PDF文件的具体步骤。首先需将iTextSharp.dll引入bin目录并添加命名空间引用,随后通过实例化Document对象设置页面尺寸,并使用PdfWriter指定输出路径。关键步骤包括在打开文档前配置作者、标题等元数据,以及通过BaseFont加载本地字体(如黑体)以解决中文显示问题,最终写入段落内容并关闭流。

2025.09.10 690
Java开源简繁转换类库 quick-chinese-transfer 推荐

介绍基于Java实现的开源简繁转换类库 quick-chinese-transfer。该库支持简体与香港繁体、台湾繁体的互转,底层采用 HanLP 词典以提升准确性。文章涵盖 Maven/Gradle/JitPack 依赖配置、基础转换 API 调用,以及通过 preLoad 方法解决冷启动耗时问题的进阶用法。

2025.05.12 690
不依赖第三方库纯PHP生成docx文件的底层实现

本文介绍如何利用PHP内置的ZipArchive类,通过直接构造符合Office Open XML标准的ZIP压缩包来生成docx文件。核心在于理解docx本质为遵循OOXML规范的ZIP格式,需正确配置[Content_Types].xml、_rels/.rels及word/document.xml等关键节点。通过示例代码演示最小化文档构建流程,并重点解决中文编码及特殊字符转义问题,确保生成的XML合法且能被Word正确识别。

2026.09.29 686
Skill 文件
  • SKILL.md
    • Read Word Document
    • Features
    • Installation
      • Prerequisites
      • Install Skill
    • Usage
      • Command Line
      • Python API
    • Examples
      • Example 1: Read and Analyze
      • Example 2: Search Keywords
      • Example 3: Batch Processing
    • API Reference
      • read_word_document(filepath)
      • search_in_document(filepath, keywords)
      • save_as_text(paragraphs, output_path)
      • analyze_document(filepath)
    • Troubleshooting
      • Error: ModuleNotFoundError: No module named 'docx'
      • Error: Legacy .doc file shows garbled text
      • Error: Chinese characters display incorrectly
    • File Support
    • Permissions
    • Security
    • Changelog
      • v1.0.0 (2026-03-20)
    • Author
    • License
  • 项目或源文件

相关 Skill

更多
Joe's Markdown to DOCX Converter Joe's Markdown to DOCX Converter 将 Markdown 文件转换为格式完整的 Word DOCX 文档,支持表格、图片、代码块以及 GitHub 风格 Markdown 功能。
IBCAT - International Bilingual Chinese Advanced Translator IBCAT - International Bilingual Chinese Advanced Translator 通过BabelDOC和LLM提取、翻译和渲染内容,生成保留原始布局的双语对照PDF。
Arc Text Icon (Upper-Arc Chinese Text) Arc Text Icon (Upper-Arc Chinese Text) 生成上弧形中文文字图标,适用于包装、印章、徽章、横幅或外标签,字符沿圆形弧线排列。
文件总结 File Summary & Analysis 文件总结 File Summary & Analysis Local document summary tool. Activate when user mentions "总结文件", "帮我总结", "总结文档", "分析文档" or provides a local file path (txt/docx/pdf/xlsx/xls).
文档内容总结 Summary & Analysis txt/docx/pdf/xlsx/xls 文档内容总结 Summary & Analysis txt/docx/pdf/xlsx/xls local document summary & analysis tool. triggers: 帮我总结, 总结文件, 分析文档, 分析总结, 总结一下, 分析一下 summarize for me, analyze for me, summarize the file, analyze the docume...