Stripping characters from windows clipboard with win32clipboard from excel

MRAB python at mrabarnett.plus.com
Thu Sep 12 21:56:53 EDT 2013


On 13/09/2013 01:58, stephen.boulet at gmail.com wrote:
> Hi Steven. Here is my code:
>
> import win32clipboard, win32con
>
> def getclipboard():
>      win32clipboard.OpenClipboard()
>      s = win32clipboard.GetClipboardData(win32con.CF_TEXT)
>      win32clipboard.CloseClipboard()
>      return s
>
> I use this helper function to grab the text on the clipboard and do useful things with it.
>
> Sorry about the description; I have stuff to learn about strings and python 3.3.
>
> To get the string length, I just do len(s). There were 10 columns and 700+ rows of data, so len(s) returned 80684 from an excel spreadsheet saved as a text file.
>
>>From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish.
>
 From my own experiments (although not with Excel) it appears that
GetClipboardData returns bytes (a bytestring), not (Unicode) strings.



More information about the Python-list mailing list