【发布时间】:2022-01-25 01:58:08
【问题描述】:
我无法在电子邮件正文中提出像 justify 或 col_space 这样的时髦论点。
这是一些示例:
import pandas as pd
from win32com import client
# software connection
outlook = client.Dispatch('Outlook.Application')
# table
df = pd.DataFrame({
'num_col': [250.0, 3.14159265359, 100000.639],
'str_col': ['Some random text', 'Another text with different width', 'So what']
})
my_table = df.to_html(index=False, justify='center', col_space=500)
# function
def to_email(text, recipient, subject):
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = subject
mail.HtmlBody = text
mail.Display(False)
# execution
to_email(my_table, 'guess@mail.com', 'Testing')
虽然对象my_table 包含规范,但窗口显示,但列的宽度没有改变并且行是左对齐的。
更新:HTML输出
print(my_table)
<table border="1" class="dataframe">
<thead>
<tr style="text-align: center;">
<th style="min-width: 500px;">num_col</th>
<th style="min-width: 500px;">str_col</th>
</tr>
</thead>
<tbody>
<tr>
<td>250.000000</td>
<td>Some random text</td>
</tr>
<tr>
<td>3.141593</td>
<td>Another text with different width</td>
</tr>
<tr>
<td>100000.639000</td>
<td>So what</td>
</tr>
</tbody>
</table>
【问题讨论】:
标签: python html pandas outlook