Install
openclaw skills install doc-processor智能文档生成引擎 - 样式感知 + 三层模板 + 动态分类 支持 Word/Excel/PDF/CSV/TXT 读取、写入、转换、合并、提取、模板填充 v2.7: 性能监控 + 用户文档 + 错误增强 v2.6: Excel 格式保持 + PDF 生成 v2.5: 批量处理 + 模板缓存 v2.4: 日志系统 +...
openclaw skills install doc-processor统一的本地文档处理工具,支持多种格式的读取、写入、转换、合并和数据提取。
| 格式 | 扩展名 | 读取 | 写入 | 转换 | 合并 | 提取 |
|---|---|---|---|---|---|---|
.pdf | ✅ | ❌ | ⚠️ | ❌ | ✅ | |
| Word | .docx | ✅ | ✅ | ✅ | ✅ | ✅ |
| Excel | .xlsx | ✅ | ✅ | ✅ | ✅ | ✅ |
| CSV | .csv | ✅ | ✅ | ✅ | - | ✅ |
| 文本 | .txt | ✅ | ✅ | ✅ | - | ✅ |
| Markdown | .md | ✅ | ✅ | ✅ | - | ✅ |
注意:
.doc 和 .xls 旧格式(需先用 LibreOffice 转换)poppler-utilsv2.7.11 起,AI 功能(AI 摘要、AI 分析)已移除,原因:
如需 AI 功能,请使用 OpenClaw 主程序的 LLM 能力:
# 1. 使用 doc-processor 读取文档
content = doc_processor.read('report.docx')
# 2. 将内容发送给 OpenClaw 的 LLM 进行摘要/分析
# (通过 OpenClaw 的消息系统或 API)
以下方法已移除或修改:
| 方法 | 原功能 | 新行为 |
|---|---|---|
ContentAdapter.__init__(ai_service_type) | AI 服务配置 | 参数已移除 |
DocumentProcessor.__init__(ai_service_type) | AI 服务配置 | 参数已移除 |
create_ai_service() | 创建 AI 服务 | 抛出 NotImplementedError |
summarize_document() | AI 摘要 | 抛出 NotImplementedError |
原代码 (v2.7.10):
processor = DocumentProcessor(ai_service_type='hybrid')
summary = processor.summarize_document('file.docx')
新代码 (v2.7.11):
# 1. 读取文档
processor = DocumentProcessor()
content = processor.read('file.docx')
# 2. 使用 OpenClaw 主程序进行 AI 处理
# (具体方式取决于 OpenClaw 的实现)
cd ~/.openclaw/workspace/skills/doc-processor
./setup.sh
安装脚本说明:
详情见:SECURITY.md
1. 安装系统依赖
# Linux (Debian/Ubuntu)
sudo apt install poppler-utils
# Linux (RHEL/CentOS)
sudo yum install poppler-utils
# macOS
brew install poppler
2. 安装 Python 依赖
# 使用默认官方源
./setup.sh
# 使用清华镜像源(中国大陆推荐)
./setup.sh https://pypi.tuna.tsinghua.edu.cn/simple
# 或使用环境变量
export PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
./setup.sh
# 其他镜像源
./setup.sh https://pypi.mirrors.ustc.edu.cn/simple
3. 验证安装
python3 check_deps.py
./scripts/doc-info.sh report.pdf
# 读取 PDF
./scripts/doc-read.sh report.pdf
# 读取 Word(包含表格)
./scripts/doc-read.sh meeting.docx
# 读取 Excel(所有 sheet)
./scripts/doc-read.sh data.xlsx
# 写入 Word
echo '{"title": "报告", "paragraphs": ["第一段", "第二段"]}' | \
./scripts/doc-write.sh -o output.docx
# 写入 Excel
echo '[["姓名", "年龄"], ["张三", 25], ["李四", 30]]' | \
./scripts/doc-write.sh -o data.xlsx
# Word 转 CSV
./scripts/doc-convert.sh table.docx table.csv
# Excel 转 Word
./scripts/doc-convert.sh data.xlsx report.docx
# PDF 转文本
./scripts/doc-convert.sh report.pdf report.txt
# 合并 Word 文档
./scripts/doc-merge.sh part1.docx part2.docx -o merged.docx
# 合并 Excel(每个文件→独立 sheet)
./scripts/doc-merge.sh q1.xlsx q2.xlsx -o yearly.xlsx
# 提取 Word 中的表格
python3 doc_processor.py --action extract \
--input report.docx --options '{"include_tables": true}'
# 提取 Excel 指定 sheet
python3 doc_processor.py --action extract \
--input data.xlsx --options '{"sheet_names": ["Sheet1"]}'
from doc_processor import DocumentProcessor
processor = DocumentProcessor(workspace="/path/to/workspace")
# 获取文档信息
info = processor.get_info("report.docx")
print(info.to_dict())
# 读取内容
content = processor.read("report.docx")
print(content.data['paragraphs'])
# 写入文档
processor.write("output.docx", {
"title": "新文档",
"paragraphs": ["内容 1", "内容 2"]
})
# 转换格式
processor.convert("input.docx", "output.csv")
# 合并文档
processor.merge(["a.docx", "b.docx"], "merged.docx")
# 提取数据
data = processor.extract("data.xlsx")
| 依赖 | 类型 | 用途 | 自动安装 |
|---|---|---|---|
| poppler-utils | 系统 | PDF 读取 | ✅ (Linux/macOS) |
| python3 | 系统 | 运行环境 | ❌ (需预装) |
| python-docx | Python | Word 处理 | ✅ (setup.sh) |
| openpyxl | Python | Excel 读写 | ✅ (setup.sh) |
| pandas | Python | 数据处理 | ✅ (setup.sh) |
Bug 修复:
{'sheet_name': '...', 'data': [...]} 格式Bug 修复:
A: 这些是旧的二进制格式,需要 LibreOffice 转换。建议先用 LibreOffice 转换为 .docx/.xlsx:
libreoffice --headless --convert-to docx old.doc
libreoffice --headless --convert-to xlsx old.xls
A: 不支持。PDF 是只读格式。如需生成 PDF,可先创建 Word 文档再手动转换。
A: 建议使用 --options 限制读取范围:
# 只读取 PDF 前 5 页
python3 doc_processor.py --action read \
--input large.pdf --options '{"pages": "1-5"}'
MIT License