python - Python 3: pretty_html_table returning HTML text rather than table
问题描述
I'm writing a script to email a pandas dataframe as a table to several people. I have my dataframe frame
:
SITE ... VISITS
438 1 ... 104
439 2 ... 104
440 3 ... 104
504 4 ... 215
I'm trying to create a pretty_html_table that I can email using:
from pretty_html_table import build_table
html_table = build_table(frame, 'blue_light')
However, instead of emailing a table, the script emails a bunch of html text!
<p><table border="0" class="dataframe">
<thead>
<tr style="text-align: right;">
<th style = "background-color: #FFFFFF;font-family: Century Gothic;font-size: medium;color: #305496;text-align: left;border-bottom: 2px solid #305496;padding: 0px 20px 0px 0px">SITE</th>
etcetera, etcetera ...
I'm trying to append this table to an email like so:
import win32com.client as win32
def report_email(email):
html_table = build_table(frame, 'blue_light')
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = email
mail.Subject = 'Table below'
mail.Body = "Hi, here is a table" + html_table
return mail.Send()
Thanks so much for all you help!
解决方案
pretty_html_table.build_table
预计会返回表格的 HTML 代码。问题是您使用mail.Body
. 改为使用mail.HTMLBody
。
推荐阅读
- java - 如何在 JAVA 客户端中添加 JSON 输入
- c - 如何向字节添加和提取位?
- vba - 如何在 VBA 中确定自定义拼写词典是否处于活动状态?
- java - 线程“主”java.lang.UnsatisfiedLinkError 中的异常:java.library.path 中没有数学
- excel - Excel VBA 宏中难以捉摸的“错误 400” - 无法理解原因
- treeview - UI5树表为什么重复节点?
- java - 几个小时后停止前台服务
- php - 如果 Woocommerce 购物车中有“错误”通知,请不要重定向到结帐
- spring-boot - SpringBoot应用监控添加Timed注解导致报错
- arm-template - 我们如何使用 ARM 模板在 Function App 中添加新的主机密钥