Convert .doc/.docx/.xlsx to Markdown and install as an OpenCode skill (optional .doc -> .docx via pywin32 on Windows)
Project description
convert-documents-skill
这是一个 Python 实现的文档转换工具(以 PyPI 为发布目标)。它将 .doc/.docx 转为 Markdown,并将 .xlsx 转为包含每个 Sheet 的 Markdown。输出会包含同名文件夹、.md 文件以及 _images/ 图片文件夹。并且它可以被安装为 OpenCode 的自定义 skill,以 slash 命令形式直接调用。
使用(推荐 Python 方式)
-
在虚拟环境中安装依赖:
python -m venv .venv .venv\Scripts\activate # Windows pip install -r requirements.txt
-
运行转换:
python convert_documents_skill.py path/to/file.docx
说明:
- 支持 .docx(默认)和 .xlsx(Sheet -> Markdown)。
- 额外支持:.doc(需要 Windows + MS Word + pywin32)。脚本会尝试通过 COM 将 .doc 转为 .docx 后再处理;若未安装 pywin32 或 MS Word,会输出友好的报错信息。
- 还支持安装为 OpenCode skill:安装包后优先执行
python -m convert_documents_skill_install,会把SKILL.md写入 OpenCode 全局 skill 目录。
输出:在源文件同级目录生成一个同名文件夹,里面包含 .md 和 _images/。
注意事项
- 若要转换 .doc(旧格式),请在 Windows 上安装 Microsoft Word 并 pip install pywin32。脚本会在转换失败时打印明确错误。
- 如果你的文档很复杂,mammoth 的转换结果可能需要人工校对。
Publishing
To publish to PyPI:
- Ensure pyproject.toml and setup.cfg are updated with your metadata.
- Build distributions: python -m build
- Upload: python -m twine upload dist/*
在 OpenCode 中使用本 skill(推荐方式)
-
安装 Python 包
pip install convert-documents-skill
-
安装为 OpenCode 全局 skill
python -m convert_documents_skill_install
如果你的系统 PATH 已包含 Python Scripts 目录,也可以使用:
install-convert-documents-skill
这会把
SKILL.md写入 OpenCode 全局 skill 目录。安装器会优先探测你机器上已经存在的 OpenCode skills 根目录(例如~/.config/opencode/skills),避免写到 OpenCode 实际不读取的位置。完成后,重启或重新加载 OpenCode。 -
在 OpenCode 中直接使用 slash 命令
/convert-documents
然后提供文件路径,例如:
请把
D:\\docs\\策划案.docx转成 Markdown。Skill 会优先使用安装时对应的 Python 解释器去执行:
python -m convert_documents_skill "<file-path>" -
如果只想使用 CLI,也可以直接运行:
convert-docs /workspace/input/design.docx
-
OpenCode 集成注意事项
- 若只处理 .docx/.xlsx,Linux 容器即可;若需要处理 .doc(旧格式),必须在 Windows 且安装 MS Word + pywin32。
- 推荐在 OpenCode 流程中只传入 .docx/.xlsx;若仍需支持 .doc,请在预处理步骤中把 .doc 转为 .docx,或在 Windows 节点执行。
- 若 OpenCode 中调用失败,通常是因为运行环境与安装包所在 Python 环境不一致;重新在 OpenCode 使用的同一环境中执行
pip install convert-documents-skill与python -m convert_documents_skill_install。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file convert_documents_skill-0.1.3.tar.gz.
File metadata
- Download URL: convert_documents_skill-0.1.3.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e721aeed786e3187fe58c52b4fb4bebe50ef0d182d4e514ad3fe77dc802ea200
|
|
| MD5 |
aa3fa34412c22d974916bb641632515d
|
|
| BLAKE2b-256 |
7e2237ced99e290cd0583a3a046548ccd8945d4812f6f0582a7000c96c9ddafd
|
File details
Details for the file convert_documents_skill-0.1.3-py3-none-any.whl.
File metadata
- Download URL: convert_documents_skill-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac961f656a595a723c17804a855f95eef61ea904d4bc0bef735ca50b764e76a1
|
|
| MD5 |
768f5ccc1909db351192e79c1c675924
|
|
| BLAKE2b-256 |
7244a67f9f41f26aea8121763a81e4239b606bb95faaf3e142924ed32cbd5be3
|