首先需要安装 pandoc 程序,pypandoc 是用来调用该程序来完成工作的。 工具获取: 小蓝枣的csdn资源仓库

转换代码如下:
代码语言:javascript复制# -*- coding:utf-8 -*-
import pypandoc
# html文档的位置
html_path = r"C:UsersAdministratorDesktophtml_to_wordsonar.html"
# 转换生成word文档的位置
word_path = r"C:UsersAdministratorDesktophtml_to_wordsonar.docx"
pypandoc.convert_file(html_path, 'docx', outputfile=word_path)
原文档:

转化后效果图:

原文档:

转化后效果图:

喜欢的点个赞❤吧!


