0

I am currently using python with the openpyxl library to move data from my program to an excel sheet. I am now trying to copy a set range to the clipboard as if I copied if from the sheet itself so that it would paste like a block (as excel does when copying a range), is there a way of doing this?

Thank you!

Update: so I installed pywin32 and I imported win32clipboard just fine. I tried to copy with that using this

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(17, ws['A1':'F{}'.format(i)] )
win32clipboard.CloseClipboard()

and I received the error as following;

File "C:\Users\victoriom\My Documents\LiClipse Workspace\Dot\Main.py", line 394, in CalculateFunc
win32clipboard.SetClipboardData(17, ws['A1':'F{}'.format(i)] )
TypeError: 'tuple' does not support the buffer interface

I thought that maybe it was because I was using the wrong data format so I tried all the excel type (I can provide the list if it helps but its about 30 different numbers) but everyone one gave the same error

  • Read this http://stackoverflow.com/questions/101128/how-do-i-read-text-from-the-windows-clipboard-from-python and than come back with your code you have tried. – stovfl Feb 22 '17 at 20:23
  • @stovfl I added the code that I tried above, thanks :) – Victorio Morello Feb 22 '17 at 21:54
  • Read This http://stackoverflow.com/questions/42195172/how-can-i-list-all-1st-row-values-in-an-excel-spreadsheet-using-openpyxl to get a clue how to get data from a range. You have to pass a String to the clippboard. Independently of this I guess Excel will past this clippboard Data in in one cell As string. Determine what Format Excel exspects to do copy and past. – stovfl Feb 23 '17 at 07:50
  • I will be dropping this idea but thank you for your help! – Victorio Morello Feb 23 '17 at 16:33

0 Answers0