使用Python将Word文档转换为HTML或Markdown |
您所在的位置:网站首页 › 怎么将word转化为html › 使用Python将Word文档转换为HTML或Markdown |
如何将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 安装Python3.8.61、勾选Add Python 3.8 to PATH加入系统变量,接着点击Customize installation(自定义安装) image.png2、可写安装包,默认全选,点击Next进入下一步 image.png3、指定Python安装路径,这边安装在C:\Python36,点击Install 开始安装 image.png4、安装中,等待安装完成 image.png5、安装完成后,点击close关闭 image.png安装Mammoth库1、使用Windows+R键(开始菜单找到运行窗口),输入cmd调出命令窗口 image.png2、在DOS窗口里输入,如为加入变量则需进入Python安装目录下的Scripts文件夹内然后运行pip Python pip install mammoth等到提示下载成功就可以了 image.png3、将Docx 转换为HTML 本教程操作目录为C:\ahaoyw 使用命令行 Python mammoth input_name.docx output_name.htmlimage.png使用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=markdownimage.png使用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) |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |