2017-06-18 43 views
1

我從xlwings調用python代碼時無法獲得斷點。當從xlwings調用Pycharm時的斷點

testme.py:

Sub CallTestMe() 
    RunPython ("import testme; testme.xl_add()") 
End Sub 

在xlwings.bas我改變設置以::

PYTHON_WIN = "D:\Anaconda3\python.exe" 
UDF_DEBUG_SERVER = True 

import xlwings as xw 

def add(n): 
    result = [] 
    while len(result) < n: 
     result.append(1+4) 
    return result 

def xl_add(): 
    sht = xw.Book.caller().sheets[0]   
    n = sht.range('B1').options(numbers=int).value 
    seq = add(n) 
    sht.range('C1').expand('vertical').clear_contents() 
    sht.range('C1').options(transpose=True).value = seq 

if __name__ == "__main__": 
    xw.serve() 

我在同一目錄中與此VBA代碼保存的XL片

然後我啓動了pycharm並在add(n)中設置了一個斷點,並啓動了調試器。

D:\Anaconda3\python.exe "D:\Program Files\JetBrains\PyCharm Community Edition 2017.1.4\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 18601 --file D:/sletmig/xlwings/testme.py 
pydev debugger: process 8684 is connecting 

Connected to pydev debugger (build 171.4694.38) 
xlwings server running, clsid={506E67C3-55B5-48C3-A035-EED5DEEA7D6D} 

我所說的VBA代碼,並返回5秒的排在C列但沒有斷點被擊中。在單元格B1我有編號10

的軟件版本
Pycharm社區版2017.4
xlwings v0.10.4
的Python 3.6.1 ::阿納康達4.4.0(32位)
辦公室2013 32位
視窗10中,64位

回答

0

只可能設定在UDF函數斷點喜歡這些:

@xw.func 
def double_sum(x, y): 
    """Returns twice the sum of the two arguments""" 
    return 2 * (x + y)     

def main(): 
    # To run this with the debug server, set UDF_DEBUG_SERVER = True in the xlwings VBA module 
    xw.serve() 

if __name__ == '__main__': 
    main() 

斷點是在Pycharm中啓動服務器並從XL = DOUBLE_SUM(1,2)

相關問題