win32clipboard operation

L

LeeRisq

Hi all,

Newbie question. I've written a script that outputs to a text file.

Now, I just want to copy the content to win32clipboard for access to
other applications. Here's the mess I've come up with so far:)

import xlrd
import win32clipboard



def program_uno():
ofile = open(r"C:\Query\DQL.txt", "w")
book = xlrd.open_workbook("C:\DocLoader\MCL_Drawing and Legacy
Docloader Sheet.xls")
sh = book.sheet_by_index(0)
e = sh.cell_value(1, 0)
a = sh.col_values(0, start_rowx=2, end_rowx=200)
b = r'%' + e
c = r'%Draft%'
y = r"some text..." %(b, c)
w = r"some more text..."
ofile.writelines(y)
for x in a:
d = r'%' + x
z = r" loop text..." %(d, c)
f = ofile.writelines(z)
ofile.writelines(w)


def copy_text():
ifile = open(r"C:\Query\DQL.txt", "r")


win32clipboard.OpenClipboard(0)
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText()
win32clipboard.CloseClipboard

program_uno()
copy_text()
 
M

MRAB

LeeRisq said:
Hi all,

Newbie question. I've written a script that outputs to a text file.

Now, I just want to copy the content to win32clipboard for access to
other applications. Here's the mess I've come up with so far:)
[snip]

def copy_text():
ifile = open(r"C:\Query\DQL.txt", "r")
text = ifile.read()
ifile.close()

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()
 
L

LeeRisq

LeeRisq said:
Newbie question. I've written a script that outputs to a text file.
Now, I just want to copy the content to win32clipboard for access to
other applications. Here's the mess I've come up with so far:)

[snip]

def copy_text():
     ifile = open(r"C:\Query\DQL.txt", "r")
     text = ifile.read()
     ifile.close()

     win32clipboard.OpenClipboard()
     win32clipboard.EmptyClipboard()
     win32clipboard.SetClipboardText(text)
     win32clipboard.CloseClipboard()

I've actually tried this configuration, but I did it again just to be
sure. The program executes without exception, but the text still isn't
copied to the clipboard. Any ideas?
 
M

MRAB

LeeRisq said:
LeeRisq said:
Hi all,
Newbie question. I've written a script that outputs to a text file.
Now, I just want to copy the content to win32clipboard for access to
other applications. Here's the mess I've come up with so far:)
[snip]

def copy_text():
ifile = open(r"C:\Query\DQL.txt", "r")
text = ifile.read()
ifile.close()

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()

I've actually tried this configuration, but I did it again just to be
sure. The program executes without exception, but the text still isn't
copied to the clipboard. Any ideas?

All I can say is that it works for me (Windows XP Pro, service pack 3).
 
L

LeeRisq

I've actually tried this configuration, but I did it again just to be
sure. The program executes without exception, but the text still isn't
copied to the clipboard. Any ideas?

So, I think I've figured out the issue. Which brings me to another
question...why is it that I can manually copy and paste the text
without issue, but when I run a python script that copies the same
text to the clipboard, it won't accept the amount of text I am placing
on the clipboard. Is there some kind of setting I am missing? Buffer
size maybe?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top