Install
openclaw skills install @sashavegal/format-flowopenclaw skills install @sashavegal/format-flow多功能的文档格式转换工具集,支持文档、网页、文本、数据表格、图片等多种格式的相互转换。
触发词:
使用示例:
# 单文件
python scripts/convert.py word2pdf document.docx
# 批量转换
python scripts/convert.py word2pdf --batch ./documents --recursive
触发词:
使用示例:
# 转换并提取图片
python scripts/convert.py word2md document.docx
# 批量转换
python scripts/convert.py word2md --batch ./documents
# 不提取图片
python scripts/convert.py word2md document.docx --no-images
触发词:
使用示例:
python scripts/convert.py pdf2md document.pdf
python scripts/convert.py pdf2md --batch ./pdfs
触发词:
使用示例:
python scripts/convert.py md2word document.md
python scripts/convert.py md2word --batch ./markdown
触发词:
使用示例:
# 从URL转换
python scripts/convert.py web2md https://example.com
# 从HTML文件转换
python scripts/convert.py web2md page.html
# 批量转换HTML文件
python scripts/convert.py web2md --batch ./html_files
触发词:
使用示例:
# 完整格式化
python scripts/convert.py textfmt notes.txt --operations normalize titles paragraphs
# 添加行号
python scripts/convert.py textfmt code.txt --operations line_numbers
# 生成大纲
python scripts/convert.py textfmt document.txt --operations outline
支持的格式化操作:
normalize: 规范化空白字符和标点titles: 格式化标题(添加下划线)paragraphs: 格式化段落(统一缩进)lists: 格式化列表line_numbers: 添加行号outline: 提取大纲toc: 生成目录timestamp: 添加时间戳触发词:
使用示例:
# 记录格式(默认)
python scripts/convert.py excel2json data.xlsx --format records
# 分组格式
python scripts/convert.py excel2json data.xlsx --format grouped --group-by category
# 嵌套格式
python scripts/convert.py excel2json data.xlsx --format nested --group-by department,name
# 数组格式
python scripts/convert.py excel2json data.xlsx --format array
# 指定工作表
python scripts/convert.py excel2json data.xlsx --sheet "Sheet2"
JSON 格式说明:
records: 对象数组 [{"name": "Alice", "age": 30}, ...]grouped: 按列分组 {"group1": [records...], ...}nested: 多级嵌套分组array: 行数组 [[headers...], [row1...], ...]触发词:
使用示例:
# 默认质量(85)
python scripts/convert.py imgcompress photo.jpg
# 指定质量(0-100)
python scripts/convert.py imgcompress photo.png --quality 70
# 批量压缩
python scripts/convert.py imgcompress --batch ./images --quality 80
触发词:
使用示例:
# 转换为JPEG
python scripts/convert.py imgconvert photo.png --format jpeg
# 转换为PNG
python scripts/convert.py imgconvert photo.jpg --format png
# 转换为WEBP
python scripts/convert.py imgconvert photo.jpg --format webp
# 批量转换
python scripts/convert.py imgconvert --batch ./images --format webp
触发词:
使用示例:
# 固定尺寸
python scripts/convert.py imgresize photo.jpg --width 800 --height 600
# 只指定宽度(高度自动计算)
python scripts/convert.py imgresize photo.jpg --width 800
# 比例缩放
python scripts/convert.py imgresize photo.jpg --scale 0.5
# 批量调整
python scripts/convert.py imgresize --batch ./images --scale 0.8
查看所有功能的可用性:
python scripts/convert.py --status
输出示例:
Document Converter v3.0 - Status Check
Document Conversions:
Word → PDF: Available (docx2pdf)
Word → Markdown: Available
PDF → Markdown: Available
Markdown → Word: Available (pypandoc)
Web Processing:
Web → Markdown: Available
Text Processing:
Text Formatting: Available
Data Conversion:
Excel → JSON: Available (openpyxl)
Image Processing:
Image Compress: Available (Pillow)
Image Convert: Available (Pillow)
Image Resize: Available (Pillow)
scripts/
├── convert.py # 主入口 (CLI)
│
├── converters/ # 转换器模块
│ ├── word_to_pdf.py # Word → PDF
│ ├── word_to_markdown.py # Word → Markdown
│ ├── pdf_to_markdown.py # PDF → Markdown
│ ├── markdown_to_word.py # Markdown → Word
│ ├── web_to_markdown.py # 网页 → Markdown
│ ├── text_formatter.py # 文本格式化
│ ├── excel_to_json.py # Excel → JSON
│ └── image_processor.py # 图片处理
│
└── utils/ # 工具模块
├── dependencies.py # 依赖管理
└── helpers.py # 辅助函数
| 转换类型 | 文本质量 | 格式保留 | 图片处理 | 表格支持 | 综合评分 |
|---|---|---|---|---|---|
| Word → PDF | ★★★★★ | ★★★★★ | ★★★★★ | ★★★★★ | 5.0 |
| Word → Markdown | ★★★★★ | ★★★★☆ | ★★★★★ | ★★★★☆ | 4.8 |
| PDF → Markdown | ★★★★☆ | ★★★☆☆ | ✗ | ★★★☆☆ | 3.5 |
| Markdown → Word | ★★★★★ | ★★★★☆ | ★★★★☆ | ★★★★☆ | 4.5 |
| Web → Markdown | ★★★★☆ | ★★★★☆ | ★★★★☆ | ★★★★☆ | 4.2 |
| Text Formatting | ★★★★★ | ★★★★★ | - | - | 5.0 |
| Excel → JSON | ★★★★★ | ★★★★★ | - | ★★★★★ | 5.0 |
| Image Processing | - | ★★★★★ | ★★★★★ | - | 5.0 |
pip install python-docx pdfplumber Pillow tqdm
pip install docx2pdf # Word → PDF (Windows + MS Word)
pip install pypandoc # 增强 Markdown → Word
pip install beautifulsoup4 # Web → Markdown
pip install openpyxl # Excel → JSON
文档发布: Word → Markdown (★★★★★) 文档归档: Word → PDF (★★★★★) 内容编辑: Markdown → Word (★★★★☆) 内容提取: PDF → Markdown (★★★☆☆)
处理大量文件时使用批量模式:
python scripts/convert.py word2md --batch ./documents --recursive
使用静默模式进行自动化:
python scripts/convert.py word2pdf document.docx --quiet
原因: docx2pdf 需要 Microsoft Word(仅 Windows)
解决方案: 安装 LibreOffice
# Ubuntu/Debian
sudo apt-get install libreoffice
# macOS
brew install libreoffice
原因: 扫描版 PDF 或复杂布局
解决方案: 使用 OCR 工具预处理
ocrmypdf input.pdf output.pdf
原因: 网络问题或网站反爬
解决方案:
原因: 编码问题
解决方案: 确保源文件为 UTF-8 编码
添加新转换类型的步骤:
scripts/converters/ 创建新模块convert_TYPE1_to_TYPE2() 函数converters/__init__.pyconvert.py 添加 CLI 命令MIT License - 详见 LICENSE 文件
scripts/convert.py - 主入口scripts/converters/ - 转换器模块scripts/utils/ - 工具函数README.md - 详细使用指南SKILL.md - 本文档快速开始: python scripts/convert.py --help