This topic outlines the components of the data feed application, and the data flows between the components.
Components
There are four components involved in providing a real-time data feed in Excel.
As you will see in the following section, Flows, the data flows required to manage real-time data in Excel can be quite complicated. The XllRtdFeed RTD server and the C++ API supplied in XllRtdFeedServerProxy.h abstract most of this complexity and make the process of developing a data feed add-in much simpler.
Flows
The data flow between Excel and the various components of a real-time feed is described below.
Excel calls add-in function
When Excel calls the add-in function for the first time, the following steps occur:
-
Excel calls the add-in function in the XLL.
-
The add-in function requests the data from the feed, and registers an interest in updates to the data.
-
The feed either returns the current value for the data, or returns a success code, indicating that the data will be sent later, asynchronously.
-
The add-in function informs the RTD server that this data is real-time, and may be updated at a later time. This is done by calling the function CXllRtdFeedServerProxy::CallRtd().
-
The add-in function returns the current value (or a "Wait" message) to Excel.
The data feed sends an update
From time to time the data feed will send data asynchronously to the XLL add-in. This may be because a data value previously supplied has been updated, or because a data value previously requyested is now available.
-
The data feed sends a message when an interesting data item is updated. This is received by a call-back function in the XLL add-in, and may occur in a background thread.
-
The XLL's call-back function informs the RTD server that this particular topic has changed.
-
Whenever Excel is ready for input, the RTD server informs Excel that the topic's value has changed.
After this, Excel will call the add-in function again for any cell that refers to the updated topic, and the data flow will be as discussed above under Excel calls add-in function.
If calculation in Excel is set to Automatic, then a recalculation will occur as soon as Excel receives the update message. If calculation is set to Manual, then the affected cells will be recalculated the next time F9 is pressed.
A spreadsheet containing real-time data is reopened
When a spreadsheet is opened that contains real-time data formulae, Excel may need to refresh the real-time values. The following steps occur:
-
Excel informs the RTD server that it wants up-to-date values for the topics used in the spreadsheet.
-
The RTD informs the XLL by invoking the IXllRtdFeedCallback::OnGetDataState() event handler function, which is implemented in the XLL.
-
During IXllRtdFeedCallback::OnGetDataState(), the XLL requests the latest value of the data item from the data feed.
-
The feed either returns the current value for the data, or returns a success code, indicating that the data will be sent later, asynchronously.
-
The XLL's implementation of IXllRtdFeedCallback::OnGetDataState() returns a state value which describes the current value of the requested data item.
-
The RTD server returns the state value to Excel. Excel compares it to the last state value it received for this data item, and decides whether the value is out of date.
After this, Excel will call the add-in function again for any cell that refers to the reopened topic, and the data flow will be as discussed above under Excel calls add-in function.