问题描述
关于此主题的问题已经存在多个,但是显然没有一个问题可以从df.style
生成到Outlook。
问题是:丢失某些df
格式,将样式化的df添加到Outlook电子邮件正文中,而不会丢失保存相同的df as df.html
文件。
def Emailer(message,subject,recipient):
import win32com.client as win32
outlook = win32.dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = subject
mail.GetInspector
print(mail.HTMLbody[:index + 1] + \
message + mail.HTMLbody[index + 1:])
mail.HTMLbody = mail.HTMLbody[:index + 1] + \
message + mail.HTMLbody[index + 1:]
mail.display(True)
数据框样式器
#format header
#format odd rows
#format hover
df_style=df.style.set_table_styles(
[{'selector': 'th','props': [('background-color','#4DAA21'),('color','#0F110D'),('font-size','15')]},{'selector': 'tr:nth-of-type(odd)','#CBDEC3')]},{'selector': 'tr:hover','#7FE9F0')]},]
)
渲染样式化的df
with open('DataFrame.html','w') as f:
f.write(df_style.hide_index().render() )
f.close
html = df_style.hide_index().render()
通话功能
Emailer(html,Subject,"[email protected]")
我尝试使用to_html
,但这在格式上受到限制。
我尝试检查生成的css
字符串,但没有立即发现。
我已经回到文档中,由于文件格式正确,因此清除格式是正确的。
我认为问题在于抓取{@ {1}}并为其编制索引。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)