Install
openclaw skills install @paudyyin/document-proopenclaw skills install @paudyyin/document-pro赋予 AI 强大的文档处理能力:
| 格式 | 读取 | 写入 | 工具 |
|---|---|---|---|
| ✅ | ✅ | pdfplumber, pypdf, reportlab | |
| DOCX | ✅ | ✅ | python-docx |
| PPTX | ✅ | ✅ | python-pptx |
| XLSX | ✅ | ✅ | openpyxl |
| TXT | ✅ | ✅ | 内置 |
| Markdown | ✅ | ✅ | 内置 |
# 提取文本
import pdfplumber
with pdfplumber.open("document.pdf") as pdf:
for page in pdf.pages:
text = page.extract_text()
print(text)
# 提取表格
with pdfplumber.open("document.pdf") as pdf:
table = pdf.pages[0].extract_tables()
from docx import Document
doc = Document("document.docx")
for para in doc.paragraphs:
print(para.text)
# 提取表格
for table in doc.tables:
for row in table.rows:
print([cell.text for cell in row.cells])
from pptx import Presentation
prs = Presentation("presentation.pptx")
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
print(shape.text)
import openpyxl
wb = openpyxl.load_workbook("data.xlsx")
ws = wb.active
for row in ws.iter_rows(values_only=True):
print(row)
1. 识别文档类型 → 选择正确的工具
2. 读取内容 → 提取文本、表格、图片
3. 分析信息 → 理解结构、提取要点
4. 总结呈现 → 用中文总结给用户
向用户呈现文档时:
| 问题 | 原因 | 解决方案 |
|---|---|---|
| PDF 文本为空 | 扫描件/图片型 PDF | 使用 OCR(pytesseract + pdf2image) |
| Word 表格丢失 | 复杂嵌套表格 | 使用 python-docx 的 table.rows 遍历 |
| PPT 图片无法提取 | 嵌入方式不同 | 检查 shape.shape_type,使用 Image 对象 |
| Excel 日期格式错误 | 序列号未转换 | 使用 openpyxl 的 dateutil 解析 |
| 编码乱码 | 文件编码非 UTF-8 | 尝试 gbk、latin1 等编码 |
| 文件损坏 | 下载不完整或格式错误 | 尝试用 Office 软件修复,或重新获取文件 |
def check_document_dependencies():
"""检查文档处理依赖是否可用"""
missing = []
packages = {
'pdfplumber': 'PDF 文本提取',
'pypdf': 'PDF 基础操作',
'docx': 'Word 文档处理',
'pptx': 'PowerPoint 处理',
'openpyxl': 'Excel 处理',
}
for package, desc in packages.items():
try:
__import__(package)
except ImportError:
missing.append(f"{package} ({desc})")
if missing:
print("缺少以下依赖:")
for m in missing:
print(f" - {m}")
print(f"\n安装命令: pip install {' '.join(p.split()[0] for p in missing)}")
return False
print("所有文档处理依赖已就绪!")
return True
文档处理优先级:
1. 专用库(pdfplumber/python-docx/python-pptx)→ 最佳效果
2. 通用库(pypdf/内置读取)→ 基础功能
3. 命令行工具(pdftotext/libreoffice)→ 最后手段
4. 提示用户手动转换 → 无法处理时
完成任务后,做任务总结,将操作记录更新到 record.md 中。
Version 1.0.1 — 增加任务完成后更新record.md规则