Translator's description: Welcome everyone to visit me
BLOG:
Http://daidaoke.donews.net/daidaoke/
My email: tangtaike@163.com
For reprint, please notify us in advance.
Chapter II Second section of the advanced function of spreadsheet components
We have discussed most of the basic functions of the spreadsheet components, and now let us turn to some advanced features. Most of these advanced features Excel2000 are not included, because these are special features specialized in components. And those existing in Excel2000 are also enhanced in spreadsheet components, making some new features.
Property binding and real-time data
"Attribute Binding" is one of the latest new features in the spreadsheet component, which means the ability to use the properties and methods of other objects on the same web page to be used as a unit value or formula parameter. The spreadsheet control uses a standard COM mechanism to be bound to the properties, and the data source object is notified when the value has changed, and the new value is automatically received, and the associated unit is recalculated.
For example, if you have developed a component, it discloses some attributes and methods to return a final sales price for a given stock code, you can use the spreadsheet control to view this information and observe its changes in the price update. . If the other parts of the spreadsheet - such as the current user's combination information (
Translator Note: Terms of Financial Professionals. ) - Quote This final sales price, then the spreadsheet component will recalculate these units when the value changes.
You can establish an attribute binding like this below in the unit:
= Document.stockther.quote ("msft"). Lastsale
As long as the formula begins with "= Document.", The spreadsheet component considers that it is a property binding. It will believe that the next part of the expression will be the ID of the other element on the page, and the rest of the expression will attribute the element, or an attribute of another element returned by a method. You can use the unit reference as parameters in the method call, and the spreadsheet control will inevitably pass the real value to the method.
The object that the unit bind to the unit can be another COM object, or any HTML element on the page, such as a text box or a drop-down list. This way you can include other data on the page directly, without having to write the script to enter the value of the HTML element into the spreadsheet cell.
Attribute binding mechanisms are often mentioned in environments that provide real-time data because it contains two must-provide features that provide dynamic data.
l When you know that the property is modified, the spreadsheet component immediately updates the unit without having a fixed polling interval.
l "Even if the user edits other units or executes the command," the spreadsheet component will continue to listen to the new value and update the unit. One of the general complaints of the Excel's DDE link mechanism is that it cannot complete this feature, so we are sure that the same error should be avoided in the property binding characteristics of the spreadsheet control.
Can the property binding point to the spreadsheet component itself?
Bold readers may already think of the possibility of binding units in the spreadsheet assembly to the component itself, or binding the possibility on another spreadsheet component. (Thinking Wildly) From the surface, it seems to be able to pass this mechanism, easy to support units on different spreadsheets.
But, hey, this is impossible. The spreadsheet control itself prohibits this support because the re-entry references and cyclic references may be quite horrible. The spreadsheet control only knows that it is bound to another (not itself or another spreadsheet control) - so it cannot ensure that the reference does not generate a dependency loop that will hang the rejuvenation chain.
To achieve the unit associated with the unit in the current spreadsheet component to another electronic table component, you must pass the code in another component to respond to the Change event and write the new value into the associated cell.
Of course, remember that the ability of the spreadsheet component processing attribute change notification is completely dependent on the time of its rejuvenation. For small and medium-sized models, there is usually no problem, because the return will only cost a second or less time - more than the data update time that most people can tolerant. However, if the model is quite huge, the spreadsheet control can only be rebuilt as soon as possible to provide new values, which may be much slower than the new value arrived. In Chapter 10 will tell more details about attribute binding. In this chapter, you will see how to create a stock market control system in Visual Basic, providing real-time quotes for stock portfolios.
Function plugin
As in Excel, developers can use the function plug-in to add new features into the spreadsheet component. Unlike the plug-ins that comply with the Excel private XLL model, the function plugin of the spreadsheet component is created in a COM object. Any method published by this object is added in the form of internal functions (
Translator Note: What is Potential Function? ), You can use it in the formula to use it like those Excel internal functions.
For example, if you have developed a COM object, a method called SUMTOPN that returns the previous N-bit value according to the incoming number of values, then you can use this function with the following code in the spreadsheet component. Just like in the Window_onLoad event:
Spreadsheet1.addin myObject
MyObject variables should point to an instance of a custom function object. To ensure your object is available, use the