2017-05-26 77 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