I know when you copy formatted text from Google Docs and paste it elsewhere, like Word, it can preserve the colour and formatting. Is there a way to decode such clipboard contents with python so that when it's a string I can tell which parts are coloured / formatted differently?
import win32clipboard
win32clipboard.OpenClipboard()
k = win32clipboard.GetClipboardData()
print(k)
data = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
ok = data.encode('UTF-8')
print(ok)
ok2 = data.encode('UTF-16')
print(ok2)
ok3 = data.encode('windows-1252')
print(ok3)
now = data.encode('utf_8').decode('utf_8')
print(now)
print(win32clipboard.GetClipboardData())
win32clipboard.CloseClipboard()
the code above is me trying to examine what the clipboard looks like...
I'm expecting my clipboard to have a few sentences in different colours. My goal is to split the clipboard contents at where the formatting changes, but I'm at a loss for what direction I should be approaching this. Can this be done solely through Python? Or should I be looking into converting the source text file before copying it to the clipboard for reading?
Very similar question: Copying formatted text from Text widget in tkinter but the suggestion here, 'pyperclip', seems to only handle plaintext.