Pasting python's tabulate output to Microsoft Office editors
<p>Quite frequently I need to copy-paste small tables from an SQL editor into Microsoft Office programs (Outlook and OneNote) and I want it to look nice as I paste it. So I wrote a short script taking the data from the clipboard, processing it with Tabulate and returning it to the clipboard.
This works very well when I paste the new table into Notepad++ and other editors. It completely messes up when I paste into Outlook. 
If I paste into Notepad++ and then copy paste from there, everything's fine.<br>
I tried the different table formats, and I tried playing around with Outlook's editor options.</p>

<p>Would really appreciate any insights! </p>

<p>Thanks!</p>

<p>See code:</p>

<pre><code>import win32clipboard
import pandas as pd
from tabulate import tabulate

df = pd.read_clipboard()
head = df.columns.tolist()
val = df.values

table =  tabulate(val,headers=head,tablefmt="grid")

# set clipboard data
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(str(table))
win32clipboard.CloseClipboard()
</code></pre>