python怎样在excel中应用?-Python教程

资源魔 43 0

python正在excel中使用的办法:起首【return sorted(s)】正在内陆建设一个目次,并保留这个代码并定名为【Methods.py】;而后关上Excel,填写一些数据以便提供python剧本解决;最初备挪用python剧本便可。

python正在excel中使用的办法:

正在Excel中预备挪用的python代码:

def merge_sort_unique(lists):
     s = set()
     for L in lists:
      s.update(L)

return sorted(s)恣意正在内陆建设一个目次,并保留这个代码并定名为Methods.py。咱们一步步看看若何从Excel的工作表中若何挪用这个剧本。关上Excel,填写一些数据以便提供python剧本解决,并放弃这个表格于方才的python剧本正在同一目次下。你的工作表应该以下:

0a4e5958ceb8bd55289de710d1fe88c.png

接上去,关上VBA并提交给ExcelPython。

关上VBA按 Alt + F11 而后进入对象界面的 References···假如你曾经正确装置了ExcelPython你能够从对话框落选择。

9cf49f953f64cc83e0f80bb34e41446.png

如今,备挪用python剧本,创立一个新的模块(Insert | Module)并敲如下VBA代码:

Function msu(lists As Range)
    Set methods = PyModule("Methods", AddPath:=ThisWorkbook.Path)
    Set result = PyCall(methods, "merge_sort_unique", PyTuple(lists.Value2))
    msu = WorksheetFunction.Transpose(PyVar(result))
    ExitFunction
EndFunction

相干学习保举:python视频教程

以上就是python怎么正在excel中使用?的具体内容,更多请存眷资源魔其它相干文章!

标签: excel Python python教程 python编程 python使用问题

抱歉,评论功能暂时关闭!