【问题标题】:Mailing with win32com not rendering to_html() arguments使用 win32com 发送邮件不呈现 to_html() 参数
【发布时间】:2022-01-25 01:58:08
【问题描述】:

我无法在电子邮件正文中提出像 justifycol_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


    【解决方案1】:

    不支持以下样式(最小宽度:500px):

    <th style="min-width: 500px;">num_col</th>
    <th style="min-width: 500px;">str_col</th>
    

    Outlook 使用 Word 呈现邮件正文的 HTML 标记。您可以在Word HTML and CSS Rendering Capabilities in Outlook 文章中找到支持和不支持的 HTML 元素、属性和级联样式表属性。

    【讨论】:

    • 感谢您的参考。但是,我没有看到它直接帮助我解决问题。关于如何设置函数以正确呈现表格的任何提示?
    • 好吧,我没有在您的帖子中找到完整的标记。如果没有发布完整的 HTML 标记,怎么会有人提出任何建议?
    • 对不起,我刚刚编辑了帖子!
    猜你喜欢
    • 2017-05-25
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 2013-06-17
    • 2014-05-06
    • 2012-02-10
    • 1970-01-01
    相关资源
    最近更新 更多