Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use Threading and Dynamic Array Formulas #1277

Closed
Colin-b opened this issue Mar 19, 2020 · 1 comment · Fixed by #1293
Closed

Allow to use Threading and Dynamic Array Formulas #1277

Colin-b opened this issue Mar 19, 2020 · 1 comment · Fixed by #1293
Milestone

Comments

@Colin-b
Copy link
Contributor

Colin-b commented Mar 19, 2020

Hi,

For now dynamic array formulas are prefixed with the implicit intersection operator (@) when using threading on generated user defined functions.
Meaning that a single value is shown instead of the expected array.

import xlwings as xw

@xw.func(async_mode='threading')
def many_values():
    return ["test", "test2"]

image

The issue comes from the fact that Range.Formula is used when updating the formula to trigger a new call retrieving the cached result:

apps[self.pid].books[self.book].sheets[self.sheet][self.address].formula = \

Leading to the underlying use of Range.Formula as in the following:

def formula(self):

Switching to Range.Formula2 fixes the issue.
image

I will gladly provide a pull request but I was wondering about the design approach for this fix, so first I would like to check with you if the following can be merged:

However I would point out that I don't have access to a Mac then I am unable to test the behavior on Mac, that's why I am proposing to use a try/except block on the operation, as I am unaware of the result.

Also, I don't have access to a version of Microsoft Excel that does not have Range.Formula2, so I am unable to test the behavior when Range.Formula2 is not available, that's why I am proposing to use a try/except block on the operation, as I am unaware of the result.

According to my tests, Range.Formula2 works fine with arrays and single value return types.

@fzumstein
Copy link
Member

Mac currently doesn't support UDFs, so you don't have to worry about that part. You'll most likely get a pywintypes.com_error if the formula doesn't exist, so try/except sounds good. I'll be able to test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants