[英]Python 3: pretty_html_table returning HTML text rather than table
我正在為 email 和 pandas dataframe 寫一個腳本,作為幾個人的表格。 我有我的 dataframe frame
:
SITE ... VISITS
438 1 ... 104
439 2 ... 104
440 3 ... 104
504 4 ... 215
我正在嘗試創建一個可以使用 email 的 pretty_html_table:
from pretty_html_table import build_table
html_table = build_table(frame, 'blue_light')
但是,腳本不是通過電子郵件發送表格,而是通過電子郵件發送一堆 html 文本!
<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 ...
我正在嘗試將此表 append 轉換為 email,如下所示:
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()
非常感謝你的幫助!
pretty_html_table.build_table
預計會返回表的 HTML 代碼。 問題是您使用mail.Body
。 請改用mail.HTMLBody
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.