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

Access vba or caller in converter for UDFs #1541

Closed
audetto opened this issue Mar 11, 2021 · 5 comments
Closed

Access vba or caller in converter for UDFs #1541

audetto opened this issue Mar 11, 2021 · 5 comments

Comments

@audetto
Copy link

audetto commented Mar 11, 2021

I would like to know if it is possible to access vba or caller inside a converter.

The use case is a function returning an object which is saved into a python dictionary and the key returned to Excel.
I would like to use the cell name to avoid constantly creating new objects.

I could do this inside the function, but I like the idea of the converter so that I keep this Excel logic separated. And when calling it from python, it does not alter the behaviour.

Moreover I could use a decorator around the function, but that would alter the normal python behaviour.

I really like the idea of the converters.

Any suggestion?

@audetto audetto changed the title Access vba or caller in converter Access vba or caller in converter for UDFs Mar 11, 2021
@fzumstein
Copy link
Member

If you could add an example, that would certainly help. Converters are only good for manipulating the values, but you might be able to pull something off by writing an Accessor. Since they are currently not documented, you could take a look at one here:
https://github.com/xlwings/xlwings/blob/master/xlwings/conversion/standard.py#L168-L182

@audetto
Copy link
Author

audetto commented Mar 12, 2021

I will provide an example, but meanwhile I found a way to achieve it

excel = xw.apps.active
application = excel.api.Application
caller = excel.Caller

address = caller.Address

This works in converters, even if they don't have access to the caller provided by xw.

@fzumstein
Copy link
Member

I'd rather use xw.Book.caller().app instead of xw.app.active

@audetto
Copy link
Author

audetto commented Mar 12, 2021

here is an example

https://github.com/audetto/xlwings-demo/blob/master/main.py

in particular, https://github.com/audetto/xlwings-demo/blob/master/main.py#L16

With this technique, objects are never deleted.

The idea is almost the same as get_cache_key in

def get_cache_key(func, args, caller):

But with the suggestion above, once can bypass the whole caller thing. Are there any drawbacks?

@fzumstein
Copy link
Member

I am closing this as I think it's a dupe of #555.

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

No branches or pull requests

2 participants