跳到正文
Skillpedia
PDF、Word 与幻灯片7.8k · #12866

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-read-fallback/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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_file fails, times out, or returns errors on .docx files
  • execute_code_sandbox attempts 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

  1. Try read_file on the .docx file
  2. If it fails, verify python-docx availability
  3. Use run_shell with the python-docx extraction command
  4. Parse the stdout to get document content
  5. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能