xlladdins / xll

Excel add-in library
MIT License
104 stars 23 forks source link

Excel Web Service Function #18

Open aperth opened 2 years ago

aperth commented 2 years ago

Hello,

I am trying to use the Excel function xlfWebservice to fetch the JSON of a web API and although the function works as expected, making multiple simultaneous calls to that function in Excel is pretty slow. Do you know if there is a way to use the multithreaded recalculation capabilities explained here: https://docs.microsoft.com/en-us/office/client-developer/excel/multithreaded-recalculation-in-excel? Here's my C++ code:

AddIn xai_test(
    Function(XLL_LPOPER, "xll_test", "TEST")
    .Arguments({Arg(XLL_LPOPER, "url", "is a URL to retrieve.")})
    .FunctionHelp("Return contents of URL.")
);
LPOPER WINAPI xll_test(LPOPER url)
{
#pragma XLLEXPORT
    static OPER f;

    f = Excel(xlfWebservice, *url);

    return &f;
}
keithalewis commented 2 years ago

Try https://github.com/xlladdins/xll_inet. It is not async, but it might be fast enough. Still a work-in-progress so let me know if you run into any infelicities.

keithalewis commented 2 years ago

I've updated xll_inet with an async version of \URL.VIEW called URL.VIEWA. Feedback welcome.

aperth commented 2 years ago

Hello,

Thank you for this update! I tried to build and install the add-in in Excel but I get the following error: "Failed to register: \MEM_VIEW". Do you know what's causing this issue?

keithalewis commented 2 years ago

I don't know, but I'll find out and let you know. That is just a warning. Everything else should work, just not the async \URL.VIEWA. Try \URL.VIEW("https://google.com") and VIEW(h, 0, 100) to get the first 100 characters of the result.

aperth commented 2 years ago

Unfortunately \URL.VIEW does not work either. I have a feeling that win::mem_view is causing the issue. It is used by both \URL.VIEW and \MEM_VIEW.

aperth commented 2 years ago

FYI I cloned a previous version of the repo (commit 13e95f63a) and \URL.VIEW works fine. The speed is still an issue however.

keithalewis commented 2 years ago

It was not clear to me that the old \URL.VIEWA was being registered as async, hence my latest fiddling.

aperth commented 1 year ago

Have you been able to resolve the issue of \URL.VIEWA? Currently \URL.VIEW and \URL.VIEWA do not work.

keithalewis commented 1 year ago

No. It is not a priority for me.

keithalewis commented 1 year ago

I have figured out how to get async working in Excel UDFs. Seeasync.cpp Let me know if that helps you fix \URL.VIEWA.