Hi i'd like to refresh all RTD function's data from excel command

547 views
Skip to first unread message

Sam.Park

unread,
May 18, 2011, 1:02:08 AM5/18/11
to Excel-DNA
Hi

I am developing RTD function using Excel-DNA to get data from remote
Server.
I'd like to make two excel command for end-user to refresh data of
RTD functions.
one excel command makes to refresh RTD functions only on Activesheet,
And
the other command make to refresh RTD functions on Active WorkBook.
How can i do this ? Any advice will be appreciated.

Regards,
Park

Ron

unread,
May 18, 2011, 4:42:17 AM5/18/11
to Excel-DNA
Hi Park,

I have something similar in my project : all the data are stored in a
cache. A menu has been added to Excel and allows the user to clear the
cache. In that case, an event is raised by the cache which is
subscribed by the RTD server, and the RTD server notifies the callback
with every topics stored.
In my case, I refresh everything, but I think you could store the rtd
topics by sheet name.
You can retrieve the sheet and book name with such a code :
ExcelReference reference =
(ExcelReference)XlCall.Excel(XlCall.xlfCaller);
string fullSheetName = XlCall.Excel(XlCall.xlSheetNm,
reference) as string; // => "[bookname]sheetName"

Regards,
Ron

Sam.Park

unread,
May 18, 2011, 11:32:38 PM5/18/11
to Excel-DNA
Hi Thanks for reply

I don't get how to implement cache object in my application. I guess
i should create a dictionary(cache) which is key is the topicid
I wonder when to add and remove topicid to cache. Also I don't get
how to refresh RTD functions which are on end-user's selected Range.
And is there any way to hook event on changing excel workbook or
worksheet

Regards,
Park

Ron

unread,
May 19, 2011, 4:16:39 AM5/19/11
to Excel-DNA
The object cache doesn't contains topicids. It just contains internal
ids (strings in my case).
The RTD server contains a dictionary with the links between internal
ids and topic ids (one internal id can be related to many topicids).

If it can help you, I will describe my workflow :

1) The user builds an object Foo with a UDF called "BuildFoo" in a
sheet range (let's say "A1"), with an internal identifier (let's call
it "FooId1") in input parameters.
BuildFoo first calls XlCall.RTD(..., FooId1,...), then it asks to the
cache whether FooId1 already exists, in that case it does nothing
more. If FooId1 didn't exist, a new Foo is created with that internal
identifier.
Finally, in all cases BuildFoo returns a string like
"FooId1::ddMMyy_hh.mm.ss" where "ddMMyy_hh.mm.ss" is a timestamp (last
update time).
The RTD server has been called by XlCall.RTD(..., FooId1,...) through
"ConnectData" interface. Thus it adds the topicid to its dictionary
(Dictionary<string, int>, where "int" value is for the topic id and
"string" value is the internal id).

2) In another range ("B1"), the user enters a UDF call, depending on
"A1", something like "CalculateWhatever(A1, ...)".

3) Finally, something modifies the Foo object (because of another UDF
call or whatever). The cache raises an event "FooObjectModified" which
RTD server subscribed to. The event argument contains the internal
identifier of the foo object.
Then the RTD server notifies the callback (IRTDUpdateEvent given by
"ServerStart"), and store the internal id in a temporary list.
Finally, "RefreshData" will return an Array containing all the
topicids related to the stored internal ids (don't forget to clear the
temporary list after).
In that case, Excel will call again the building function in "A1",
which won't build again the Foo as it already exists in cache, but it
will just return the "FooId1::ddMMyy_hh.mm.ss" with a new timestamp
(the last update time).

4) Finally, "A1" range has been automatically updated by RTD server
(the timestamp has changed). "B1" depends on it so it will be updated
too.

I hope it's understandable.

Regards,
Ron
Reply all
Reply to author
Forward
0 new messages