如何将Word文档转换为HTML或Markdown呢?我们可以使用Python的库Mammoth 来完成转换操作
Pyton官网下载地址 :https://www.python.org/downloads/
这边使用:python-3.8.6-amd64.exe
https://www.python.org/ftp/python/3.8.6/python-3.8.6-amd64.exe
1、勾选Add Python 3.8 to PATH加入系统变量,接着点击Customize installation(自定义安装)
2、可写安装包,默认全选,点击Next进入下一步
3、指定Python安装路径,这边安装在C:\Python36,点击Install 开始安装
4、安装中,等待安装完成
5、安装完成后,点击close关闭
1、使用Windows+R键(开始菜单找到运行窗口),输入cmd调出命令窗口
2、在DOS窗口里输入,如为加入变量则需进入Python安装目录下的Scripts文件夹内然后运行pip
Python
pip install mammoth
等到提示下载成功就可以了
3、将Docx 转换为HTML
本教程操作目录为C:\ahaoyw
使用命令行
Python
mammoth input_name.docx output_name.html
使用Python代码
Python
import mammoth
with open("input_name.docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
with open("output_name.html", "w") as html_file:
html_file.write(result.value)
4、将Docx 转换为MD
使用命令行
Python
mammoth input_name.docx output.md --output-format=markdown
使用Python代码
Python
import mammoth
with open("input_name.docx", "rb") as docx_file:
result = mammoth.convert_to_markdown(docx_file)
with open("output.md", "w") as markdown_file:
markdown_file.write(result.value)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。