indexdoc-converter 文档转换工具库
indexdoc-converter 是一款基于 Python 开发的文档转换工具库,核心功能为将主流办公文档、网页文件高效转换为 Markdown 格式。各类型文件支持格式如下:
- Word 文档支持 .docx ;
- Excel 类表格文档支持 .xlsx、.xls、.ods、.csv、.tsv ;
- 网页文件支持 .html、.mhtml、.htm 及网页url ;
- PPT 演示文档支持 .pptx 。 该工具库现已发布至 PyPI(Python Package Index),可通过 pip 包管理工具快速安装并投入使用。
库的使用
#库安装
pip install -U indexdoc-converter #下载最新版本库
- 若使用该库 python版本最小应为 Python3.10
- 包目录结构
indexdoc-converter/ # 项目根目录
├── indexdoc_converter/ # 核心包目录
│ ├── __init__.py # 核心代码
│ ├── docx_to_md.py # Word转Markdown工具类
│ ├── excel_to_md.py # Excel转Markdown工具类
│ ├── html_to_md.py # Html转Markdown工具类
│ ├── pptx_to_md.py # ppt转Markdown工具类
│ └── utils/
│ ├── __init__.py
│ ├── FileUtil.py
│ ├── IDUtil.py
│ └── img_to_base64.py
使用示例
#引用 注意引用为 indexdoc_converter 而不是 indexdoc-converter
from indexdoc_converter.docx_to_md import convert_docx_to_md
from indexdoc_converter.excel_to_md import TableToMarkdown
from indexdoc_converter.html_to_md import convert_to_md
from indexdoc_converter.pptx_to_md import pptx_to_md
# -------------------------------------------Word转Markdown---------------------------------------------------
md_text = convert_docx_to_md(r"C:\Users\xxx\测试文档.docx", False)
with open('./test.md', 'w', encoding='utf-8') as f:
f.write(md_text)
# -------------------------------------------Excel转Markdown-------------------------------------------------
# 自定义参数示例
converter = TableToMarkdown(
file_title_level=2, # 文件标题的Markdown层级,默认1(#),这里设为2(##)
single_row_value_as_title=True, # 是否将单行唯一值识别为标题,默认True
max_rows=8000, # 最大处理行数,默认6000(实际处理行数是max_rows+1)
max_cols=200 # 最大处理列数,默认128(实际处理列数是max_cols+1)
)
# 转换单个文件
file_path = r"C:\Users\xxx\测试文件.xlsx"
result = converter.convert(file_path)
# blank 模式:保留合并单元格的原始样式(只在合并单元格左上角显示内容,其余位置为空)
with open("../tmp/测试_blank.md", "w", encoding="utf-8") as f:
f.write(result['blank'])
# fill 模式:将合并单元格的内容填充到所有合并的单元格中同时还能自动识别表格中的标题行、分割多个表格块,处理空行 / 空列,兼容各种表格格式的合并单元格解析。
with open("../tmp/测试_fill.md", "w", encoding="utf-8") as f:
f.write(result['fill'])
# -------------------------------------------ppt转Markdown---------------------------------------------------
ppt_file = r"C:\Users\xxx\测试文件.pptx"
md_path = pptx_to_md(ppt_file)
print(f"单文件转换完成,MD文件路径:{md_path}")
# -------------------------------------------网页文件转Markdown-----------------------------------------------
# html = "https://news.qq.com/rain/a/20260114A01NI000"
html = "https://www.aituple.com"
# html = "https://www.indexdoc.com"
# html = r"C:\Users\xxx\测试文件.html"
# html = "https://www.indexdoc.com/contact.html"
md = convert_to_md(html, '../tmp/测试html.md')
# md = mhtml_to_markdown(mhtml)
Word文档
原文档
转换后文档
Excel文档
原文档
转换后文档
ppt文档
原文档
转换后文档
网页文件
原文档
转换后文档
二次开发
- Python 3.10+
#源码地址
https://github.com/indexdoc/indexdoc-converter.git
#快速安装依赖库
pip install -r requirements.txt
# 阿里镜像源
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
📞 作者
-
作者:杭州智予数信息技术有限公司
Metadata
Release files for indexdoc-converter 0.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| indexdoc_converter-0.2.7.tar.gz | 25.6 kB | Without provenance | Details for indexdoc_converter-0.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| indexdoc_converter-0.2.7-py3-none-any.whl | Python 3 | none | any | Details for indexdoc_converter-0.2.7-py3-none-any.whl |
Total release size: 52.2 kB
Release files / indexdoc_converter-0.2.7.tar.gz
| Download URL | indexdoc_converter-0.2.7.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d8f09c5ec30227574ad4d6e823281a494443302e174c3c0ad4cfd43b3d386e5
|
|
BLAKE2b-256 checksum How to use checksums |
cd0a620980baf728324c68a513ac29e72d58c77119cd5a94786235a301911dc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / indexdoc_converter-0.2.7-py3-none-any.whl
| Download URL | indexdoc_converter-0.2.7-py3-none-any.whl |
|---|---|
| Size | 26.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
24fd159d3b7d2181d696b945200452a4333982395d236e32def5eb16661efb7a
|
|
BLAKE2b-256 checksum How to use checksums |
df8a851e6ca949d2f55c9cc7c73636f5e420212a7af355a29970adb4c8bb2f5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for indexdoc-converter 0.2.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.