Python html转doc:如何将 HTML转换为Word DOCX文档?

2021年8月13日01:59:49 发表评论 1,166 次浏览

Python如何将 HTML转换为Word DOCX文档?让我们看看如何使用我们的Python API轻松地将 HTML 转换为 DOCX,下面谁Python html转doc的详细实现。

Python html转为doc相关推荐:Python docx转html详细实现

要实现Python html转doc,我们首先使用 pip 安装程序安装转换 API 客户端:

pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.Convert.git

调用 convert_web_html_to_docx以实现Python html转为doc,它接受一个 HTML 字符串作为其输入,Python html转doc完整代码如下:

from __future__ import print_function 
import time 
import cloudmersive_convert_api_client 
from cloudmersive_convert_api_client.rest import ApiException 
from pprint import pprint
# Python html转doc:配置 API 密钥授权:Apikey 
configuration = cloudmersive_convert_api_client.Configuration() 
configuration.api_key['Apikey'] = 'YOUR_API_KEY' 
# Python html转doc,如果需要,取消下面的注释以设置 API 密钥的前缀(例如 Bearer)
# configuration.api_key_prefix['Apikey' ] = 'Bearer'
# Python html转doc:创建 API 类的实例
api_instance = cloudmersive_convert_api_client.ConvertWebApi(cloudmersive_convert_api_client.ApiClient(configuration)) 
input_request = cloudmersive_convert_api_client.HtmlToOfficeRequest() # HtmlToOfficeRequest |
try: 
    # HTML to DOCX 
    api_response = api_instance.convert_web_html_to_docx(input_request) 
    pprint(api_response) 
except ApiException as e: 
    print("调用ConvertWebApi->convert_web_html_to_docx时出现异常:%s\n" % e)

Python html转doc就这么简单!此功能支持富文本格式以及图像(我们建议使用合格的 URL),希望这篇Python html转为doc可以帮助到你。

Python html转doc:如何将 HTML转换为Word DOCX文档?
Python html转doc:如何将 HTML转换为Word DOCX文档?
木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: