Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54317

Re: Stripping characters from windows clipboard with win32clipboard from excel

Newsgroups comp.lang.python
Date 2013-09-17 09:00 -0700
References <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com>
Message-ID <a394f382-6de9-4ef5-8b99-947639c8ef6d@googlegroups.com> (permalink)
Subject Re: Stripping characters from windows clipboard with win32clipboard from excel
From stephen.boulet@gmail.com

Show all headers | View raw


On Thursday, September 12, 2013 6:01:20 PM UTC-5, stephen...@gmail.com wrote:
> I have an excel file. When I select cells, copy from excel, and then use win32clipboard to get the contents of the clipboard, I have a 131071 character string.
> 
> 
> 
> When I save the file as a text file, and use the python 3.3 open command to read its contents, I only have 80684 characters.
> 
> 
> 
> Excel (and  other programs too) appends a bunch of b'\x00' (or similar) characters.
> 
> 
> 
> Is there a pythonic way to strip these out?

Odd behavior from excel. It seems as though the clipboard contents will vary according to the clipboard size. For example, in my 13 column row I select 2023 rows, copy to the clipboard, and 

def getclipboard():
    win32clipboard.OpenClipboard()
    s = win32clipboard.GetClipboardData(win32con.CF_TEXT)
    win32clipboard.CloseClipboard()
    return s

s = getclipboard()

len(s) gives me 16298.

If I select one additional row, len(s) balloons to 32767.

In the first case, s[-10:] is b'0.032573\r\n'.

In the second case, s[-10:] is b'\x008\x008\x000\x005\x00\t'

Does anyone know what is going on with that?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Stripping characters from windows clipboard with win32clipboard from excel stephen.boulet@gmail.com - 2013-09-12 16:01 -0700
  Re: Stripping characters from windows clipboard with win32clipboard from excel Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-13 00:19 +0000
  Re: Stripping characters from windows clipboard with win32clipboard from excel stephen.boulet@gmail.com - 2013-09-12 17:58 -0700
    Re: Stripping characters from windows clipboard with win32clipboard from excel MRAB <python@mrabarnett.plus.com> - 2013-09-13 02:56 +0100
    Re: Stripping characters from windows clipboard with win32clipboard from excel Neil Hodgson <nhodgson@iinet.net.au> - 2013-09-13 13:43 +1000
      Re: Stripping characters from windows clipboard with win32clipboard from excel stephen.boulet@gmail.com - 2013-09-13 07:31 -0700
        Re: Stripping characters from windows clipboard with win32clipboard from excel Neil Cerutti <neilc@norwich.edu> - 2013-09-13 14:37 +0000
        Re: Stripping characters from windows clipboard with win32clipboard from excel stephen.boulet@gmail.com - 2013-09-13 07:38 -0700
          Re: Stripping characters from windows clipboard with win32clipboard from excel random832@fastmail.us - 2013-09-13 12:09 -0400
          Re: Stripping characters from windows clipboard with win32clipboard from excel random832@fastmail.us - 2013-09-18 15:19 -0400
  Re: Stripping characters from windows clipboard with win32clipboard from excel stephen.boulet@gmail.com - 2013-09-17 09:00 -0700
  Re: Stripping characters from windows clipboard with win32clipboard from excel stephen.boulet@gmail.com - 2013-09-18 12:28 -0700
    Re: Stripping characters from windows clipboard with win32clipboard from excel MRAB <python@mrabarnett.plus.com> - 2013-09-18 20:40 +0100
    Re: Stripping characters from windows clipboard with win32clipboard from excel Dave Angel <davea@davea.name> - 2013-09-18 20:13 +0000
      Re: Stripping characters from windows clipboard with win32clipboard from excel Neil Hodgson <nhodgson@iinet.net.au> - 2013-09-19 07:40 +1000
        Re: Stripping characters from windows clipboard with win32clipboard from excel Dave Angel <davea@davea.name> - 2013-09-18 23:51 +0000
          Re: Stripping characters from windows clipboard with win32clipboard from excel Neil Cerutti <neilc@norwich.edu> - 2013-09-19 15:53 +0000
            Re: Stripping characters from windows clipboard with win32clipboard from excel Dave Angel <davea@davea.name> - 2013-09-19 19:58 +0000
    Re: Stripping characters from windows clipboard with win32clipboard from excel random832@fastmail.us - 2013-09-19 10:39 -0400

csiph-web