Xpersona
D

Doc Processor

CLAWHUB · Unverified

智能文档生成引擎 - 样式感知 + 三层模板 + 动态分类 支持 Word/Excel/PDF/CSV/TXT 读取、写入、转换、合并、提取、模板填充 v2.7: 性能监控 + 用户文档 + 错误增强 v2.6: Excel 格式保持 + PDF 生成 v2.5: 批量处理 + 模板缓存 v2.4: 日志系统 +... Skill: Doc Processor Owner: mo-yuhua Summary: 智能文档生成引擎 - 样式感知 + 三层模板 + 动态分类 支持 Word/Excel/PDF/CSV/TXT 读取、写入、转换、合并、提取、模板填充 v2.7: 性能监控 + 用户文档 + 错误增强 v2.6: Excel 格式保持 + PDF 生成 v2.5: 批量处理 + 模板缓存 v2.4: 日志系统 +... Tags: latest:2.7.13 Version history: v2.7.13 | 2026-03-28T03:15:30.222Z | user 🧹 清理 AI 残留代码 (ices 测试反馈) - 删除 create_ai_service 等残留 - 统一版本号 - 补充发布说明 v2.7.12 | 2026-03-27T14:43:27.629Z | user v2.7.12: 安全优化 (完善文档 +

62
Rank
84
Safety
1.3k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.3K downloads reported by the source. Last updated 10/10/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s17avctgwctc01vs9adtct6fv983gge4:doc-processor
  1. Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-mo-yuhua-doc-processor/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

156,469 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: doc-processor
description: |
  智能文档处理引擎 - 专注文档处理 (v2.7.11 移除 AI 功能)
  支持 Word/Excel/PDF/CSV/TXT 读取、写入、转换、合并、提取
  v2.7.11: 移除 AI 功能 (由 OpenClaw 主程序统一处理)
  v2.7.5: 路径解析 Bug 修复 + 异常体系完善
  v2.7: 性能监控 + 用户文档 + 错误增强
  v2.6: Excel 格式保持 + PDF 生成
  v2.5: 批量处理 + 模板缓存
  v2.4: 日志系统
  v2.3: Excel 模板支持 + 模板匹配智能化
homepage: https://github.com/openclaw/skills
version: 2.7.13
tags: ["document", "word", "excel", "pdf", "file", "conversion", "template", "v2", "logging", "batch"]
metadata:
  openclaw:
    emoji: "📄"
    requires:
      bins: ["pdftotext", "pdfinfo"]
    install:
      - id: brew-poppler
        kind: brew
        formula: poppler
        bins: ["pdftotext", "pdfinfo"]
        label: "Install poppler (Homebrew)"
        platforms: ["darwin"]
      - id: apt-poppler
        kind: system
        command: "sudo apt install -y poppler-utils"
        bins: ["pdftotext", "pdfinfo"]
        label: "Install poppler-utils (apt)"
        platforms: ["linux"]
      - id: python-deps
        kind: script
        script: "setup.sh"
        label: "Install Python dependencies"
tags: ["document", "word", "excel", "pdf", "file", "conversion"]
---

# 文档处理 Skill (Doc Processor)

统一的本地文档处理工具,支持多种格式的读取、写入、转换、合并和数据提取。

## 支持格式

| 格式 | 扩展名 | 读取 | 写入 | 转换 | 合并 | 提取 |
|------|--------|------|------|------|------|------|
| PDF | `.pdf` | ✅ | ❌ | ⚠️ | ❌ | ✅ |
| Word | `.docx` | ✅ | ✅ | ✅ | ✅ | ✅ |
| Excel | `.xlsx` | ✅ | ✅ | ✅ | ✅ | ✅ |
| CSV | `.csv` | ✅ | ✅ | ✅ | - | ✅ |
| 文本 | `.txt` | ✅ | ✅ | ✅ | - | ✅ |
| Markdown | `.md` | ✅ | ✅ | ✅ | - | ✅ |

**注意**:
- ❌ 不支持 `.doc` 和 `.xls` 旧格式(需先用 LibreOffice 转换)
- ✅ PDF 处理使用系统工具 `poppler-utils`

## v2.7.11 重要变更

### AI 功能已移除

**v2.7.11 起,AI 功能(AI 摘要、AI 分析)已移除**,原因:

1. **职责单一**: doc-processor 专注文档处理
2. **架构优化**: AI 能力由 OpenClaw 主程序统一提供
3. **简化配置**: 无需单独配置 LLM_BASE_URL 等环境变量
4. **提升安全**: 移除网络请求,消除 ClawHub 安全标记

**如需 AI 功能**,请使用 OpenClaw 主程序的 LLM 能力:

```python
# 1. 使用 doc-processor 读取文档
content = doc_processor.read('report.docx')

# 2. 将内容发送给 OpenClaw 的 LLM 进行摘要/分析
# (通过 OpenClaw 的消息系统或 API)
```

### 受影响的 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)**:
```python
processor = DocumentProcessor(ai_service_type='hybrid')
summary = processor.summarize_document('file.docx')
```

**新代码 (v2.7.11)**:
```python
# 1. 读取文档
processor = DocumentProcessor()
content = processor.read('file.docx')

# 2. 使用 OpenClaw 主程序进行 AI 处理
# (具体方式取决于 OpenClaw 的实现)
```

## 安装

### 一键安装

```bash
cd ~/.openclaw/workspace/skills/doc-processor
./setup.sh
```

**安装脚本说明**:
- ✅ 标准 pip 操作,安装 Python 依赖
- ✅ 依赖列表:python-docx, openpyxl, pandas, python-dotenv
- ✅ 从官方 PyPI 或可信镜像源安装
- ✅ 无恶意代码,完全开源

详情见:[SECURITY.md](SECURITY.md)

### 手动安装

**1. 安装系统依赖**

```bash
# Linux (Debi

_meta.json

{
  "ownerId": "kn723w6ktr0rhmj1n6y17qna0h83bjpy",
  "slug": "doc-processor",
  "version": "2.7.13",
  "publishedAt": 1774667730222
}

references/api-docs.md

# 文档处理参考资料

## API 文档

### Feishu Docs API
- https://open.feishu.cn/document/ukTMukTMukTM/uEjNwUjLxYjN14SM7gTN

### Python 库文档
- python-docx: https://python-docx.readthedocs.io/
- openpyxl: https://openpyxl.readthedocs.io/
- pandas: https://pandas.pydata.org/docs/
- pdfplumber: https://github.com/jsvine/pdfplumber

## 格式规范

### Open XML 格式
- DOCX: Office Open XML (ECMA-376)
- XLSX: Office Open XML Spreadsheet
- PPTX: Office Open XML Presentation

### PDF 规范
- PDF 1.7 (ISO 32000-1)
- 使用 poppler-utils 进行文本提取

## 最佳实践

### 大文件处理
- 分块读取 >100MB 文件
- 使用流式处理避免内存溢出
- 设置合理的超时时间

### 错误处理
- 捕获依赖缺失错误
- 提供清晰的安装指引
- 优雅降级(功能不可用时)

## 常见问题

### Q: 为什么不支持 .doc 和 .xls?
A: 这些是旧的二进制格式,需要 LibreOffice 转换。建议先转换为 .docx/.xlsx。

### Q: PDF 写入支持吗?
A: 不支持。PDF 是只读格式。如需生成 PDF,可先创建 Word 文档再手动转换。

### Q: 如何处理超大 Excel 文件?
A: 使用 pandas 的 chunksize 参数分块读取:
```python
pd.read_excel('large.xlsx', sheet_name='Sheet1', chunksize=1000)
```

references/best-practices.md

# 文档处理最佳实践

## 1. 依赖管理

### 系统依赖
```bash
# PDF 处理(必需)
sudo apt install poppler-utils      # Linux
brew install poppler                # macOS
```

### Python 依赖
```bash
# 使用虚拟环境
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

## 2. 性能优化

### 大文件处理
```python
# Excel 分块读取
for chunk in pd.read_excel('large.xlsx', chunksize=1000):
    process(chunk)

# PDF 限制页数
content = processor.read('large.pdf', pages='1-10')
```

### 内存管理
```python
# 使用 read_only 模式
load_workbook('large.xlsx', read_only=True)

# 及时关闭文件
with pd.ExcelWriter('output.xlsx') as writer:
    df.to_excel(writer)
```

## 3. 错误处理

```python
try:
    content = processor.read('file.docx')
except DependencyError as e:
    print(f"依赖缺失:{e}")
    print("请运行:pip install python-docx")
except FileNotFoundError as e:
    print(f"文件不存在:{e}")
except FormatError as e:
    print(f"格式不支持:{e}")
```

## 4. 安全注意事项

### 文件验证
```python
# 检查文件是否存在
if not Path(file_path).exists():
    raise FileNotFoundError(file_path)

# 检查文件类型
if path.suffix.lower() not in SUPPORTED_FORMATS:
    raise FormatError(f"不支持的格式:{path.suffix}")
```

### 路径安全
```python
# 解析绝对路径
path = Path(file_path).resolve()

# 限制在 workspace 内
if not str(path).startswith(workspace):
    raise SecurityError("路径超出工作区")
```

## 5. 测试建议

```python
# 单元测试
def test_read_word():
    processor = DocumentProcessor()
    content = processor.read('test.docx')
    assert content.type == 'word'
    assert len(content.data['paragraphs']) > 0

# 集成测试
def test_convert_word_to_csv():
    processor = DocumentProcessor()
    output = processor.convert('input.docx', 'output.csv')
    assert Path(output).exists()
```

## 6. 扩展开发

### 添加新格式支持
```python
def _read_newformat(self, path: Path) -> DocContent:
    """读取新格式"""
    # 实现读取逻辑
    return DocContent(type='new', format='text', data=content)

# 注册到 read() 方法
elif ext == '.new':
    return self._read_newformat(path)
```

### 添加新操作
```python
def compare(self, file1: str, file2: str) -> Dict:
    """比较两个文档"""
    content1 = self.read(file1)
    content2 = self.read(file2)
    # 实现比较逻辑
    return diff_result
```

README-v2.md

# doc-processor v2.0 新功能

> **⚠️ v2.7.11 重要变更**: AI 功能已移除,由 OpenClaw 主程序统一处理。
> 本文档中的 AI 相关功能(AI 摘要、AI 匹配)在 v2.7.11+ 中已不再包含。

## 🎉 重大升级

v2.0 从"文档填充工具"升级为"智能文档生成引擎"

---

## ✨ 新增功能

### 1. 样式感知

**自动识别模板样式,填充后保持格式美观**

```python
from doc_processor import DocumentProcessor

processor = DocumentProcessor()

# 提取模板样式
style_def = processor.style_extractor.extract("template.docx")
print(f"章节数:{len(style_def.sections)}")
print(f"样式:{style_def.styles}")
```

### 2. 内容适配

**根据样式要求自动适配内容**

```python
# 摘要自动总结(过长时)
adapter = ContentAdapter()
summary = adapter._adapt_summary(长文本)

# 列表格式统一
tasks = adapter._adapt_list("任务 1\n任务 2\n任务 3")
# 输出:['• 任务 1', '• 任务 2', '• 任务 3']
```

### 3. 三层模板策略

**智能选择最佳模板**

- **Level 1**: 用户提供模板 → 保存 + 学习
- **Level 2**: 历史模板匹配 → AI 多维度匹配
- **Level 3**: Style Guide 引导 → 通用规范生成

```python
# 智能文档生成
result = processor.generate(
    user_request="生成周报",
    content={"week": 12, "author": "张三"}
)
print(f"输出:{result.output_path}")
print(f"使用模板:{result.template_used}")
```

### 4. 模板填充

**支持 {{placeholder}} 语法**

```python
# 模板内容:第{{week}}周工作报告
# 数据:{"week": 12}
# 结果:第 12 周工作报告

processor.fill_template(
    template_path="template.docx",
    data={"week": 12, "author": "张三"},
    output_path="report.docx"
)
```

### 5. 用户模板管理

**自动保存和匹配历史模板**

```
~/.openclaw/workspace/user-templates/
├── registry.json          # 注册表
├── templates/             # 模板文件
│   ├── tpl_20260325_001.docx
│   └── ...
└── categories/            # 分类索引
```

---

## 📊 Style Guide

v2.0 提供通用文档样式规范:

- `style-guide.md` - 总纲
- `word-style-guide.md` - Word 规范
- `excel-style-guide.md` - Excel 规范
- `elements/` - 文档元素样式

---

## 🚀 快速开始

### 安装 v2.0

```bash
clawhub install doc-processor --version 2.0.0
```

### 使用模板填充

```python
from doc_processor import DocumentProcessor

processor = DocumentProcessor()

# 填充模板
result = processor.fill_template(
    template_path="weekly-report.docx",
    data={
        "week": 12,
        "author": "张三",
        "main_work": "完成 v2.0 开发"
    },
    output_path="week12-report.docx"
)
```

### 智能文档生成

```python
# 自动匹配历史模板或使用 Style Guide
result = processor.generate(
    user_request="生成一份周报",
    content="这周完成了 v2.0 开发,修复了 3 个 bug"
)
```

---

## 📋 兼容性

### 保留的 v1.x 功能

- ✅ `read()` - 读取文档
- ✅ `write()` - 写入文档
- ✅ `convert()` - 格式转换
- ✅ `merge()` - 文档合并
- ✅ `extract()` - 数据提取

### 新增的 v2.0 功能

- ➕ `fill_template()` - 模板填充
- ➕ `generate()` - 智能生成
- ➕ `StyleExtractor` - 样式提取器
- ➕ `ContentAdapter` - 内容适配器

---

## 🎯 使用场景

### 场景 1: 周报生成

```python
# 第一次:上传模板
processor._save_user_template("my-weekly.docx", "生成周报")

# 后续:自动生成
result = processor.generate("生成周报", {"week": 12})
```

### 场景 2: 批量合同

```python
# 使用模板批量生成
for client in clients:
    processor.fill_template(
        "contract-template.docx",
        {"client": client, "amount": 10000}
    )
```

---

## 📚 文档

- [Style Guide](templates/style-guide.md)
- [Word 规范](templates/word-style-guide.md)
- [Excel 规范](templates/excel-style-guide.md)

---

*版本:v2.0.0 | 发布日期:2026-03-25*

Sponsored

Ads related to Doc Processor and adjacent AI workflows.