Paste Excel clip to body of an email through Python

浪尽此生 提交于 2020-01-03 03:00:29

问题


I am using win32com.client in Python to send an email.

However I want the body of the email to be a table (HTML- formatted table), I can do it in an Excel first and then copy and paste (but how?), or directly edit the corresponding Pandas data frame.

newMail.body = my_table which is a Pandas data frame didn't work.

So I'm wondering if there is smarter ways for example, to combine Excel with Outlook apps within Python?

Cheers,


回答1:


There are solutions regarding how to convert your Excel table to HTML here: How do I save Excel Sheet as HTML in Python?, and then you just drop the HTML into the body of your email.

Per request in the comments:

Once you have the HTML-formatted version of your table in a file called mytable.html, you can drop it into the email with: newMail.body = open("mytable.html").read()



来源:https://stackoverflow.com/questions/24028115/paste-excel-clip-to-body-of-an-email-through-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!