简体   繁体   English

Excel中的Python脚本输入和输出

[英]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. 我有一个非常简单的python脚本,其中要求用户输入股票购买价格,脚本查找价格并返回用户是涨还是跌。

Currently the input, and text output are done in the CMD prompt which is not ideal. 当前,输入和文本输出是在CMD提示符下完成的,这并不理想。 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. 我希望在excel中有一个用于输入购买价格的框,一个要按下的按钮,然后是一个打印输出的单元格。

Is there any straightforward ways to put the python code in the button code where you would normally have VBA? 有什么简单的方法可以将python代码放入通常具有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. 为了获得更好的帮助,您可能需要提交Python代码,以便人们可以看到您的脚本正在实现什么,并将您带入正确的道路。

Perhaps this might help How to call python script on excel vba? 也许这可能有帮助。 如何在excel vba上调用python脚本? , calling a Python script from VBA. ,从VBA调用Python脚本。

For windows, the win32com package will allow you to control excel from a python script. 对于Windows,win32com软件包将允许您从python脚本控制excel。 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.. 您可以使用提供蝙蝠文件的xlwings为您完成工作。

You just write your python to a string, and call RunPython(pythonScript) 您只需将python编写为字符串,然后调用RunPython(pythonScript)

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

xlwings page : http://xlwings.org/ xlwings页面: http ://xlwings.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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