How to create an Excel Real-Time Data Server
in Visual Studio: VB.NET, C#, C++
Creating Excel RTD servers
On this page you will find a step-by-step example of building a Real-Time Data server for Excel XP, 2003, 2007, 2010, 2013 and Excel 2016. The sample project demonstrates how you create an Excel RTD server handling a single topic.
A bit of theory
The RTD Server technology (introduced in Excel 2002) is used to provide the end user with a flow of changing data such as stock quotes, currency exchange rates etc. If an RTD server is specified in a formula (placed on an Excel worksheet), Excel loads the RTD server and waits for new data from it. When data arrive, the RTD server notifies Excel. This can be done as many times as required and every time you do this, Excel simply notes that the RTD server wants to give it an update. When Excel is ready for the update, it asks the RTD server for new data. Add-in Express allows using this mechanism in two ways:
Excel RTD Server terminology:
An Excel RTD Server can be registered either for the current user (the user running the installer) or for all users on the machine. That's why the corresponding module type, ADXRTDServerModule, provides the RegisterForAllUsers property. Registering for all users means writing to HKLM and that means the user registering a per-machine RTD server must have administrative permissions. Accordingly, RegisterForAllUsers = Flase means writing to HKCU (=for the current user).
Before you modify the RegisterForAllUsers property, you must unregister the add-in project on your development PC and make sure that adxloader.dll.manifest is writable.
Step 1. Creating an RTD server project
Make sure that you have administrative permissions before running Visual Studio. Run Visual Studio via the Run as Administrator command.
In Visual Studio, open the New Project dialog and navigate to the Extensibility folder.
Choose Add-in Express RTD Server and click OK. This starts the RTD server project wizard.
In the first wizard window, you choose your programming language (C#, VB.NET and C++.NET are supported):
When in the window below, choose Generate new or specify an existing .snk file and click Next. If you do not know anything about strong names or do not have a special strong name key file, choose Generate new. If you are in doubt, choose Generate new. If, later on, you need to use a specific strong name key file, you will be able to specify its name on the Signing tab of your project properties; you are required to unregister your add-in project before using another strong name.
The project wizard creates and opens a new solution in the Visual Studio IDE.
The solution contains an only project, the RTD server project. The project contains the RTDServerModule.vb (or RTDServerModule.cs) file discussed in the next step.
Step 2. Excel RTD module
RTDServerModule.vb (or RTDServerModule.cs) is the core part of the RTD server project. The module is a container for ADXRTDTopic components. It is a descendant of the ADXRTDServerModule class implementing the IRtdServer COM interface and allowing you to manage server's topics and their code.
To review its source code, right-click the file in the Solution Explorer and choose View Code in the context menu.
In the code of the module, pay attention to the CurrentInstace property. It returns the current instance of the RTD module. This is useful for example, when you need to access a method defined in the module from the code of another class.
Step 3. RTD Server module designer
The module designer allows setting real-time data server properties and adding components to the module.
In the Solution Explorer, right-click the RTDServerModule.vb (or RTDServerModule.cs) file and choose the View Designer popup menu item.
This opens the designer of the Excel RTD module:
Click the designer surface when you need to set properties of your real-time data server in the Properties window. The RegisterForAllUsers property shown in the screenshot above is described in Per-user and per-machine RTD servers. The Interval property sets the internal timer that causes Excel to generate the RefreshData event for topics of your RTD server.
Step 4. Adding and handling a new topic
To add a new topic to your RTD server, you use the Add RTD Topic command that places a new ADXRTDTopic component onto the module. Select the newly added component and, in the Properties window, enter string values identifying the topic in the String## properties. In this sample, the My Topic string in the String01 property identifies the topic.
It is possible to enter an asterisk (*) in any of the String## properties. When there is no ADXRTDTopic corresponding to the identifying strings entered by the user, Add-in Express creates a new ADXRTDTopic and passes it to the RefreshData event handler of the topic containing an asterisk (*). In that event, you can cast the Sender argument to ADXRTDTopic and get actual strings from its String## properties.
Now add the RefreshData event handler and write your code:
Step 5. Running the RTD server in Excel
Choose the Register Add-in Express Project item in the Build menu, restart Excel, and enter the RTD function to a cell.
If you use an Express edition of Visual Studio, the Register Add-in Express Project item is located in the context menu of the RTD module's designer surface).
See Control Panel | Regional Settings for the parameters separator.
Step 6. Debugging the RTD server
To debug your RTD server, just specify Excel as the Start Program in the Project Options window.
The table below provides links to step-by-step instructions for deploying RTD servers. Find background information in Deploying Office extensions.
Table 3. Deploying RTD servers: links to step-by-step instructions
You may want to check the following sections under Add-in Express tips and notes:
An interesting series of articles describing the creation of a real project from A to Z is available on our blog. The starting point is Building a Real-Time Data server for Excel.