Practical examples and syntax for Excel RTD functions

Source: Internet
Author: User
Tags object model

One, RTD function syntax

RTD (Progid,server,topic1,[topic2],...)

function function: Full display all hidden from support COM automation (COM add-ins: Supplemental programs that extend the functionality of Microsoft Office programs by adding custom commands and specified features.) COM Add-ins can run in one or more Office programs. The COM add-in uses the file name extension. dll or. exe. To retrieve the real-time data in the program.

Parameter description

ProgID installed on the local computer, registered COM Automation Add-ins: Supplemental programs that provide custom commands or custom features for Microsoft Office. ProgID name, which is enclosed in quotation marks.

The name of the server running the add-in by server. If there is no server and the program is running on the local computer, the parameter is blank. Otherwise, the name of the server is raised in quotation marks (""). If you are in Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): Microsoft Visual Basic's Macro language version, for writing based on Microsof T Windows applications, which are placed in multiple Microsoft programs. , you must enclose the server name in double quotes or give it a VBA nullstring property, even if the server is running on the local computer.

Topic1, Topic2,... is 1 to 253 parameters, which are put together to represent a unique real-time data.

The RTD COM Automation add-in must be created and registered on the local computer. If you do not have a live data server installed, an error message appears in the cell when you try to use the RTD function. If the server continues to update the results, unlike other functions, the RTD formula will be changed in automatic calculation mode in Microsoft Excel.

Practical examples of RTD functions

=parsearraydata (RTD ("Excelrtd.rtdfunctions", "AAA"))

=RTD ("Mycomaddin.progid", "Lorem_ipsum", "Price")

Using RTD in Excel is very simple, and Excel provides a new worksheet function RTD that allows for real-time data retrieval by calling the Component Object Model (COM) Automation server. The RTD worksheet function uses the following syntax:

"=rtd (ProgID, Server, String 1, String 2, ...) String N) "

The first variable ProgID represents the programmatic identifier (ProgID) of the Real-time Data server (RTD server). The Server variable indicates the name of the computer running the RTD server, or if the RTD server is running locally, you can set this variable to an empty string or ignore it. Other variables represent only the parameters sent to the RTD server; Each unique combination of these parameters represents a "subject" (topic), each subject has an associated subject ID (topic ID). These parameters are case-sensitive. For example, the following shows an RTD server call that will generate three different topic IDs:

=RTD ("Excelrtd.rtdfunctions", "AAA", "10")

=RTD ("Excelrtd.rtdfunctions", "AAA", "5")

=RTD ("Excelrtd.rtdfunctions", "AAA", "5")

To use the Excel RTD function, you must register a COM component that implements the IRtdServer interface. The COM component that implements this interface is the so-called RTD Server. IRtdServer has the following members:

ServerStart (Callbackobject)

Callbackobject is a irtdupdateevent type parameter that has a UpdateNotify method that notifies Excel that updated data is available (push). This way Excel will refresh all the topics (pull) by calling the RefreshData method. Call the ServerStart method when Excel requests the first RTD theme for RTD server, which returns 1 on success and returns a negative value or 0 on failure. This method will not be invoked again when other RTD functions are applied later.

ConnectData (TopicID, Strings, Getnewvalues)

Among them, Topcid uniquely identifies the application of this function in Excel, and even copying multiple copies to different cells is only one topic for Excel. This topicid is returned by Excel, and we need to record it to provide updated data for it. Strings is a System.Array that receives the arguments passed in by the RTD function (String 1...String n), which is a parameter of a reference type. Getnewvalues is used to determine whether the most recent data is always obtained, and if this parameter is passed in true, each time the Excel document is saved and reopened again, it is not necessarily the last saved data, but the most recent real-time data, which is also a parameter of a reference type.

Whenever a new theme (TOPIC) is applied to the excel,connectdata, it is invoked. Here, you need to save incoming new topicid and query parameters for later data usage. To do this, you need to define your own data structure.

DisconnectData (TopicID)

Like ConnectData, Topcid uniquely identifies an application of this function in Excel. When we remove a topic from Excel (delete all the RTD functions with the same parameters), DisconnectData will be called, where you can release the monitoring of the subject and no longer get new data for it.

Heartbeat

Determine if the RTD server is still available, 0 and minus numbers are unavailable, and 1 is available. Excel calls this method to determine whether the service is disconnected.

RefreshData (TopicCount)

TopicCount represents the number of topics to update, which is a reference type parameter that is used to return to Excel. We can define a clock to get data to the data source periodically, so that in the elapsed event of the clock, get the latest data and call the Xlrtdupdate member's UpdateNotify method to notify Excel that the new data is ready. This way, Excel calls the RefreshData method to update the data in the workbook.

ServerTerminate

Called when Excel no longer needs to obtain live data from the RTD server. Here, you can perform some cleanup, such as clearing the cache, turning off the clock, and so on. At this point, the lifecycle of an RTD server is over.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.