python怎样在excel中应用?

coldplay.xixi
Freigeben: 2020-07-03 11:51:08
Original
8870 人浏览过

python在excel中应用的方法:首先【return sorted(s)】在本地建立一个目录,并保存这个代码并命名为【Methods.py】;然后打开Excel,填写一些数据以便提供python脚本处理;最后备调用python脚本即可。

python怎样在excel中应用?

python在excel中应用的方法:

在Excel中准备调用的python代码:

def merge_sort_unique(lists):
     s = set()
     for L in lists:
      s.update(L)
Nach dem Login kopieren

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
Nach dem Login kopieren

相关学习推荐:python视频教程

以上是python怎样在excel中应用?的详细内容。更多信息请关注PHP中文网其他相关文章!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Neueste Artikel des Autors
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!