简体   繁体   中英

Python script input and output in excel

Afternoon,

I have a really simple python script in which user is asked to input a share purchase price, script looks up price and returns whether user is up or down.

Currently the input, and text output are done in the CMD prompt which is not ideal. I would love to have in excel a box for inputing purchase price, a button to press and then a cell in which the output is printed.

Is there any straightforward ways to put the python code in the button code where you would normally have VBA? Or alternative hacks?

Thanks in advance

To better help, you may want to submit your Python code so that one may see what your script is achieving and put you on the right path.

Perhaps this might help How to call python script on excel vba? , calling a Python script from VBA.

For windows, the win32com package will allow you to control excel from a python script. It's not quite the same as embedding the code, but it will allow you to read and write from the spreadsheet.

You can use xlwings which provide a bat file to do the work for you..

You just write your python to a string, and call RunPython(pythonScript)

vba code : http://docs.xlwings.org/en/v0.6.4/vba.html

xlwings page : http://xlwings.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM