from urllib.parse import urlencode
def office_share(url: str, embed=True, wd_print=0, wd_embed_code=0, start_on=1, wd_eaa=1, **kwargs) -> str:
"""
office类型文档在线预览
:param url: office文档在互联网的公开访问地址 http|https 开头
:param embed: 是否以嵌入形式预览
:param wd_print: 是否允许打印(word有效)
:param wd_embed_code: 是否允许查看嵌入代码(word有效)
:param start_on: 起始页面(word有效)
:param wd_eaa: 是否启用自动前移设置(ppt有效)
:return: 预览地址
"""
base_url = 'https://view.officeapps.live.com/op/'
if not embed:
return f'{base_url}view.aspx?{urlencode({"src": url})}'
url_params = {
**{
'wdStartOn': start_on,
'wdPrint': 1 if wd_print else 0,
'wdEmbedCode': 1 if wd_embed_code else 0,
'wdEaa': 1 if wd_eaa else 0,
'src': url,
},
**kwargs
}
return f'{base_url}embed.aspx?{urlencode(url_params)}'