Copying Excel Column into Clipboard via Python

Hello All, I am looking to take a column in Excel and copy it to clipboard, essentially Ctrl+C it.

Then i want to use python to take that data, open up another program (which I am able to) and essentially paste it (which i can do). My issue is i dont know how to copy a column in Excel to clipboard.

I have seen the module with win32clipboard. The issue i have with that is when i set the text for that, i can only input one text, not multiple since i will have anywhere from 1 to X amount of entries based on the excel sheet.

Thank you for your help!

Hello there!

Is there any reason for you to specific use copy and paste? I am saying that because, maybe putting all values into a variable and then just writing this variable content on another document will probably be easier.

If you need to use copy and paste with this module, you have some options:
You can concatenate all rows with a separator in a single string and than separate when you will write the values. But this is a poor solution.

You can mess around with SetClipboardData method to store the data the right way on the clipboard, but it looks like that will be not a easy task.

Sya

You may have a limitation or other reason for engaging the clipboard. Without knowing, I will offer openpyxl as an alternative.

Hey Thierri, I am trying to automate a dashboard that requires interaction with the ERP software, SAP.

One feature of this is taking a column of values and inputting into SAP. The best way to do this while observing the formatting requirements of SAP and all is to copy to the column in the same way we would ctrl+c and then pasting it into SAP. I can do the pasting into SAP. The Issue is i can not copy from excel with Python. I can do the for loops and all but that does not copy, i need to replicate ctrl+c over a range of a column.

Hey Sudsy, so I am using openpyxl but I need to copy information (ctrl+c) from a column in excel with Python and paste it into another software program to run a report. I can do all the other things, i am unable to ctrl+c a column.

I am trying to automate a dashboard that requires interaction with the ERP software, SAP.

One feature of this is taking a column of values and inputting into SAP. The best way to do this while observing the formatting requirements of SAP and all is to copy to the column in the same way we would ctrl+c and then pasting it into SAP. I can do the pasting into SAP. The Issue is i can not copy from excel with Python. I can do the for loops and all but that does not copy, i need to replicate ctrl+c over a range of a column.

Got it. I think you need to set the data to the clipboard on other format. Not string.

Maybe you can manually copy the data, then retrieve the data with the Python module. This way you can get some tip on how the data is stored on the clipboard when it is copied from Excel.