RE: [ExcelDna] Show Function Name on the Function Bar (Replay)

210 views
Skip to first unread message

Govert van Drimmelen

unread,
Sep 7, 2018, 9:58:25 AM9/7/18
to exce...@googlegroups.com
Hi Christian,

Your function should be defined as a method that returns the relevant value in C#.

For a simple function that is not async, it would look like this:

    [ExcelFunction(Name = "PRICE.LAST", Category = "CAT", Description = "Last Price (Intraday)")]
    public static object ASK([ExcelArgument(Description = "Instrument-Symbol")]object ric)
    {
        object result = "48640.07";
        return result;
    }

If you are trying to make an async function that uses the ExcelDna.Registration helper (it looks a bit like that from the code you show) then your function will declared as returning Task<object> instead of object, but you'll still be returning the object from your method:

    [ExcelFunction(Name = "PRICE.LAST.ASYNC", Category = "CAT", Description = "Last Price (Intraday)")]
    public static async Task<object> ASK_Async([ExcelArgument(Description = "Instrument-Symbol")]object ric)
    {
        object result = "48640.07";

        // Whatever code does the async fetch in here
        // await GetDataAsync(ric);

        return result;
    }


For normal functions you would not need to get the caller (via xlfCaller) or explicitly set the value of the cell (by setting .Value).

-Govert




From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Christian Rivera [christia...@gmail.com]
Sent: 07 September 2018 03:01 PM
To: Excel-DNA
Subject: [ExcelDna] Show Function Name on the Function Bar (Replay)

Hi, I've been working with Excel DNA and my adding works perfectly, but I have a question: How do I do to show the function name from the cell after this was called? (I  researched in the group some discussions about it, but I didn't find anything)

My function:

image (1).png

Next I call it and gets the correct result, but the formula is not shown
image.png


I set the cell value as below:
image (6).png


This is what i want to do:
image (2).pngimage (3).png

and be able to pull down and the formula get the next range of cells:
image (4).pngimage (5).png

This is possible with some Excel DNA method or maybe I'm setting the value in the wrong way? 

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Christian Rivera

unread,
Sep 7, 2018, 1:28:51 PM9/7/18
to Excel-DNA
Thanks for the feedback.

Yes, my method must be async.

I tried it your async example, but this error is shown when run excel: Initialization [Error] Method not registered - unsupported signature, abstract or generic.
To post to this group, send email to exc...@googlegroups.com.

Govert van Drimmelen

unread,
Sep 7, 2018, 3:56:31 PM9/7/18
to Excel-DNA
Oh - OK, then you're not using the ExcelDna.Registration helpers.
(Then I don't really understand why your initial async function was being registered.)

For the simplest async function, you would write it this way:

public static object ASK(object ric)
{
    string callerFunctionName = "ASK";
    object[] callerParameters = new object[] { ric };

    return ExcelAsyncUtil.Run(callerFunctionName, callerParameters, () => 
    {
        // Here you can do the slow work. We just sleep a while
        Thread.Sleep(5000);
        return 123.456;
    });
}


-Govert

Christian Rivera

unread,
Oct 2, 2018, 12:30:13 PM10/2/18
to Excel-DNA
Thanks a lot Govert, after finish other activities with my add-In I return to this issue and your example works fine!

Now, the function goes more complex, the UDF value must be updated via websocket, when OnMessage then return the new value. (Previously, this worked as re-write the cell value with Office Interop Excel properties, but in this way the formula is missing)

So, what a I did for this was recalling  the UDF and return the new value (to keep the formula) but only show the new value when user type Enter key into the cell. I tried using refreshAll method, but not works.

Do you have any idea how to do this?

Govert van Drimmelen

unread,
Oct 2, 2018, 2:00:00 PM10/2/18
to exce...@googlegroups.com
Hi Christian,

I think you're looking for the Real-Time Data feature of Excel (and the related features of Excel-DNA that make it easier to use).

See this series of examples for some options on how to implement in your add-in: https://github.com/Excel-DNA/Samples/tree/master/RtdClocks 

-Govert
 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Excel-DNA: Free and easy .NET for Excel
Develop Excel Conference - London, 18 October 2018


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Sent: 02 October 2018 06:30 PM
To: Excel-DNA
Subject: Re: [ExcelDna] Show Function Name on the Function Bar (Replay)

To post to this group, send email to exce...@googlegroups.com.

Christian Rivera

unread,
Oct 5, 2018, 12:18:36 PM10/5/18
to Excel-DNA

Hello again, I implemented the Real-Time Data featured in ExcelDNA in my AddIn, and as you said, that  maked it easier to use, works wonderful! Thanks again for your help.

I see this implementation reload the data (re-connect to the services) and that is nice, but in case the connection fail the function returns N/A values and don't keeps the old value

In the below image I open the file (seem the file keeps the values), then my AddIn shows "connection fail" on a MessageBox


Then, I accept the message and the functions change the values to N/A


And here the file is never  updated when I open it again although the connection is successfully. There is a way to refresh, reload, recall, or something from code to re-connect all the functions to services? 
Reply all
Reply to author
Forward
0 new messages