文档整理技能 (document-organizer)
by @byteuser1977
支持批量将旧版 Office 文档(.doc/.xls)高质量转换为 Markdown 并保持目录结构与格式完整。
clawhub install document-organizer📖 About This Skill
文档整理技能 (document-organizer)
概述
专业的文档批量处理技能,支持旧版 Office 文档(.doc/.xls)高质量转换为 Markdown,保持格式结构完整。
核心能力
✅ 格式转换
.doc → .md(LibreOffice 直接转换).docx → .md(LibreOffice 直接转换).xls → .xlsx → .md(保留表格结构).ppt → .pptx → .md(可选支持).xlsx/.pptx → .md(MarkItDown 直接处理)✅ 批量处理
✅ 质量保证
快速开始
1. 环境准备
# 安装 LibreOffice(系统级)
下载: https://zh-cn.libreoffice.org/
安装 Python 依赖
pip install markitdown[docx,xlsx]
2. 使用方法
# 交互模式(推荐)
npx skills run document-organizer命令行参数
npx skills run document-organizer --source "源目录" --output "输出目录" --type doc,xls
3. 配置
首次运行会检测 LibreOffice 路径,默认:
D:\Program Files\LibreOffice\program\soffice.exe/usr/bin/soffice/Applications/LibreOffice.app/Contents/MacOS/soffice详细功能
文档类型处理
| 源格式 | 转换流程 | 输出格式 | 质量 |
|--------|---------|---------|------|
| .doc | LibreOffice → Markdown | .md | ✅ 完美 |
| .docx | LibreOffice → Markdown | .md | ✅ 完美 |
| .xls | LibreOffice → .xlsx → MarkItDown → .md | .md | ✅ 完美 |
| .xlsx | MarkItDown → .md | .md | ✅ 完美 |
| .ppt | LibreOffice → .pptx → MarkItDown → .md | .md | ✅ 良好 |
| .pptx | MarkItDown → .md | .md | ✅ 良好 |
| .pdf | MarkItDown → .md | .md | ✅ 优秀(文本+表格)|
批量处理策略
方案一:分类批量(推荐)
批量转换所有 .doc 文件:
soffice --convert-to md *.doc批量转换所有 .docx 文件:
soffice --convert-to md *.docx
批量转换所有 .xls 文件:
soffice --convert-to xlsx *.xls → markitdown *.xlsx
批量转换所有 .ppt 文件:
soffice --convert-to pptx *.ppt → markitdown *.pptx
方案二:递归处理
扫描目录树,按文件类型分组
分别批量转换每个子目录
保持完整目录结构输出
使用示例
示例 1: 转换单个目录
# 扫描源目录
npx skills run document-organizer --source "G:\历史文档" --output "d:\知识库"
输出结构:
知识库/
├── 项目A/
│ ├── 需求文档.md
│ └── 设计文档.md
└── 项目B/
└── 会议记录.md
示例 2: 仅处理 Word 文档
npx skills run document-organizer --source "G:\docs" --output "d:\md" --filter .doc,.docx
示例 3: 处理 PDF 文档
npx skills run document-organizer --source "G:\pdfs" --type pdf --output "d:\pdf_md"
示例 4: 先扫描统计
npx skills run document-organizer --scan-only "G:\docs"
输出: 文件统计,不执行转换
配置选项
| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| --source | string | 必需 | 源目录路径 |
| --output | string | ./output | 输出目录 |
| --type | string | doc,xls,docx,xlsx,ppt,pptx,pdf | 处理的文件类型(逗号分隔) |
| --soffice-path | string | 自动检测 | LibreOffice soffice.exe 路径 |
| --log-file | string | conversion.log | 日志文件路径 |
| --dry-run | bool | false | 仅模拟,不实际转换 |
性能参考
测试环境: i5 CPU, 16GB RAM, SSD
| 操作 | 数量 | 耗时 | 吞吐 | |------|------|------|------| | .doc → .md (LibreOffice) | 1,000 | ~30 秒 | 33 个/秒 | | .xls → .xlsx (LibreOffice) | 2,000 | ~1.5 分钟 | 22 个/秒 | | .xlsx → .md (MarkItDown) | 2,000 | ~2 分钟 | 17 个/秒 | | .ppt → .pptx (LibreOffice) | 500 | ~30 秒 | 17 个/秒 | | .pptx → .md (MarkItDown) | 500 | ~1 分钟 | 8 个/秒 | | .pdf → .md (MarkItDown) | 500 | ~2 分钟 | 4 个/秒 | | 总计 (3,000文件) | 3,000 | ~10-12 分钟 | - |
常见问题
Q: LibreOffice 找不到?
A: 确保安装并添加到 PATH,或通过--soffice-path 指定:npx skills run document-organizer --soffice-path "C:\Program Files\LibreOffice\program\soffice.exe"
Q: 转换失败怎么办?
A: 检查错误日志,常见原因:~$ 开头)自动跳过Q: 可以预览而不转换吗?
A: 使用--dry-run 参数:npx skills run document-organizer --source "docs" --dry-run
输出: 将转换 X 个文件,Y 个目录,跳过 Z 个
Q: 如何只转换特定子目录?
A: 结合--filter 和路径模式:npx skills run document-organizer --source "docs" --filter "00_模板/*.doc"
技术架构
┌─────────────────┐
│ 用户命令 │
│ npx skills ... │
└────────┬────────┘
│
▼
┌─────────────────────────────────────────────┐
│ 文档整理技能 (Python) │
│ • 扫描目录树 │
│ • 按类型分组 (doc/xls/docx/xlsx) │
│ • 调用 LibreOffice 批量转换 │
│ • 调用 MarkItDown 结构化转换 │
│ • 保持目录结构 + 重命名 │
│ • 错误处理 + 日志记录 │
└─────────────────────────────────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐
│ LibreOffice │ │ MarkItDown │
│ (格式转换) │ │ (结构化输出) │
└─────────────────┘ └──────────────────┘
│ │
└───────────┬───────────┘
▼
┌─────────────┐
│ .md 文件 │
│ (可搜索) │
└─────────────┘
依赖清单
| 工具 | 版本要求 | 用途 | |------|---------|------| | LibreOffice | 7.0+ | .doc → .docx / .xls → .xlsx | | Python | 3.10+ | 脚本运行 | | markitdown | 0.1.5+ | .docx/.xlsx → .md | | pywin32 | (可选) | Windows COM 自动化(备用)|
脚本文件
本技能包含以下脚本:
| 文件 | 说明 |
|------|------|
| scripts/batch_convert.py | 主脚本 - 批量文档转换(支持 .doc/.xls/.docx/.xlsx/.ppt/.pptx/.pdf)|
使用建议
✅ 推荐场景
❌ 不推荐场景
strings 命令即可)版本历史
--temp-dir 参数
- 更新:完善所有支持的文件类型说明
- 优化:文档与实际脚本保持一致最后更新: 2026-03-12 适用平台: Windows/Linux/macOS (需 LibreOffice) 许可证: MIT
📋 Tips & Best Practices
Q: LibreOffice 找不到?
A: 确保安装并添加到 PATH,或通过--soffice-path 指定:npx skills run document-organizer --soffice-path "C:\Program Files\LibreOffice\program\soffice.exe"
Q: 转换失败怎么办?
A: 检查错误日志,常见原因:~$ 开头)自动跳过Q: 可以预览而不转换吗?
A: 使用--dry-run 参数:npx skills run document-organizer --source "docs" --dry-run
输出: 将转换 X 个文件,Y 个目录,跳过 Z 个
Q: 如何只转换特定子目录?
A: 结合--filter 和路径模式:npx skills run document-organizer --source "docs" --filter "00_模板/*.doc"