docx-read-fallback
它能做什么
这项技能向 AI 展示,当较简单的方法失败时,如何使用 python-docx 库提取 .docx 文件中的文字、表格和标题。它适合需要读取 AI 无法打开的 Word 文档的人。
适用场景
- ✓当文件读取器在读取 .docx 文件时失败或超时的时候。
- ✓当我需要获取 Word 文档中的文字、表格或标题的时候。
- ✓当代码沙箱无法读取 Word 文件的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-read-fallback/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“AI 无法打开我的 Word 文件。请提取其中的文字和所有表格。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会在 shell 中运行一条简短的 Python 命令,使用 python-docx 打印文件中的段落、表格或标题。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
DOCX Read Fallback
When read_file or execute_code_sandbox fails to read .docx files, use run_shell with python-docx as a reliable workaround.
When to Use
read_filefails, times out, or returns errors on.docxfilesexecute_code_sandboxattempts to read the docx fail- You need to extract text content from a Word document
- Multiple standard approaches have been exhausted
How to Use
Basic Text Extraction
python -c "import docx; doc = docx.Document('path/to/file.docx'); print('\n'.join([p.text for p in doc.paragraphs]))"
Using run_shell Tool
run_shell command="python -c \"import docx; doc = docx.Document('path/to/file.docx'); print('\n'.join([p.text for p in doc.paragraphs]))\"" timeout=60
Extract Paragraphs with Indices
python -c "import docx; doc = docx.Document('file.docx'); [print(f'P{i}: {p.text}') for i, p in enumerate(doc.paragraphs) if p.text.strip()]"
Extract Tables
python -c "import docx; doc = docx.Document('file.docx'); [[print([[cell.text for cell in row.cells] for row in table.rows]) for table in doc.tables]]"
Extract Headings (by style)
python -c "import docx; doc = docx.Document('file.docx'); [print(p.text) for p in doc.paragraphs if p.style.name.startswith('Heading')]"
Prerequisites
Ensure python-docx is available:
python -c "import docx; print('docx available')"
If not installed:
pip install python-docx
Tips
- Use absolute paths to avoid working directory issues
- Set appropriate
timeout(30-60 seconds for large documents) - Escape quotes properly when embedding in shell commands
- For large documents, extract content in chunks or filter by paragraph index
- This approach bypasses file type detection issues in read_file
Example Workflow
- Try
read_fileon the .docx file - If it fails, verify python-docx availability
- Use
run_shellwith the python-docx extraction command - Parse the stdout to get document content
- Proceed with your analysis using the extracted text
常见问题
什么是 python-docx?
它是一个用于读写 Word 文件的 Python 库。
它也能读取表格吗?
能。指南包含一条可以打印表格内容的命令。
需要安装什么?
指南说,在运行命令之前必须先安装 python-docx。
详情
作者的原始描述
Use run_shell with python-docx as reliable fallback when read_file fails on .docx files
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12866
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。