0

I have a python function which takes few required arguments together few default arguments, but when I tried as fzumstein mentioned it doesn't works as expected. What am I doing wrong?

def Doublesum(a, b=1):  
    return (a + b)**2  

In excel:

=Doublesum(1)  

This returns no value, i.e., #Value!. I have installed xlwings version 0.7.2.

Dom
  • 1,687
  • 6
  • 27
  • 37
Anbu
  • 108
  • 2
  • 9
  • Have you decorated the function with `@xw.func` and imported them into Excel? Do other functions (without default args) work? Try to download the UDF samples from the homepage and try them first. – Felix Zumstein Jun 29 '16 at 08:13
  • @FelixZumstein yes it was decorated with '@xlfunc'. yes functions without default args works. – Anbu Jun 29 '16 at 10:48
  • What version of python are you using? Out of curiosity, I just tried your example (with @xw.func) and it worked fine. Trying to narrow down the potential differences. – Paul Jul 01 '16 at 17:25
  • @Paul I'm using python 2.7.11. I think may be this is the issue, I was not able to import UDF's if I import xlwings as xw and use '@xw.func', coz i get this Runtime error, Key error from line 197 xlpyserver. But if I change it to from xlpython import * and use '@xlfunc', it imports. I couldn't figure out why but it has something to do with Anaconda!. How can i get around this? – Anbu Jul 02 '16 at 03:57

1 Answers1

0

I would recommend trying a new install in a conda environment (as it looks like you have that). Try:

conda create -n xlwings-test python=2.7
activate xlwings-test
conda install xlwings pandas numpy

Try then doing from xlwings import func. Then try the UDF example -- i.e. download the two files (.py and .xlsm) and open the .xlsm in the same command prompt that you are using for your xlwings-test environment.

That worked when I just tried it (on windows). If you keep getting that stack trace about the keyerror then please post it.

Paul
  • 5,473
  • 1
  • 30
  • 37
  • Thanks for the response, I created a new environment in the way you have mentioned above. But this I wasnt able to import udf's. Wrong number of arguments or invalid property assignment warning from Microsoft visual basic for applications. – Anbu Jul 06 '16 at 06:02