2017-05-26 79 views
1

下面的代码片段:如何将VBA输出发送到Python脚本?

' Send the query in the body to Jira, and get the response from Jira 

strJsonResponse = Utilities.JiraRequest(strJQLQuery) 

我希望把这个JSON转换为Python语法分析器,然后返回解析JSON返回到电子表格。这可能吗?我以前从未使用过VBA。

我已经下载了JIRA API模块和openpyxl模块。

+2

如果你想[用Python解析](https://jira.readthedocs.io/en/master/),你为什么打扰VBA? – Tehscript

+0

请在这里显示VBA是如何相关的。 * Jira *仅作为VBA参考使用? – Parfait

回答

1

您可能能够创建一个新的文本文件和输出VBA到

Dim fso As Object 
Set fso = CreateObject("Scripting.FileSystemObject") 
Dim Fileout As Object 
Set Fileout = fso.CreateTextFile("C:\your_path\vba.txt", True, True) 
Fileout.Write strJsonResponse 
Fileout.Close 

VBA code found here

然后有VBA启动你的Python脚本,你可以有蟒蛇解析您的文件。可能有更好的方法来做到这一点,但我不知道是什么。

0

我认为Tehscript提出了一个有效的问题。除了Python代码之外,您是否确实需要使用VBA代码?通过运行使用openpyxl模块的Python代码,您可以完全读出并修改Excel文件中的所有内容,而无需运行Excel应用程序。

有时会有耦合VBA和Python代码的正当理由。最常见的一种情况是,您想要将Excel用作熟悉的图形用户界面来指导数据操作操作,但希望Python执行实际的繁重工作。如果你想要这样做,那么有xlwings模块。 Xlwings使得它很容易到call Python code from inside VBA modules, and to exchange data values between VBA and Python