Adding a Custom Function Library to the Spreadsheet Component

[Previous] [Next]

Before you can use any of your custom functions, you must use the Spreadsheet component's AddIn method to pass the instance pointer of your COM object to the Spreadsheet component. You should do this in whatever event your container raises when the form or page is initialized. In a Visual Basic form, this is the form's Load event. The following code comes from that event in the custom function test form:

 ' Create the custom function library, and ' add it into the Spreadsheet control Set m_flCustom = New CustomFunctions ssTest.AddIn m_flCustom 

The CustomFunctions class is a public class in the analysis functions library. It is a COM object that supports IDispatch, as are all public classes defined in a COM DLL or COM EXE Visual Basic project. Because the Spreadsheet component needs a live instance of your COM object, this code first creates an instance, assigning it to the form-level variable m_flCustom. It then passes the instance pointer to the Spreadsheet component's AddIn method.

When you call the AddIn method, the Spreadsheet component examines all unknown function references in the model and resolves them if they are public functions in the class you just added. This enables you to enter references to your custom functions in a designer (as I have done in the custom function test form), even though your code has not yet added the custom function library.

You can add as many custom function COM objects as you want, and the Spreadsheet component merges all public methods into one flat namespace. The Spreadsheet component resolves functions by searching through the add-in object list in the order in which the objects were added and stopping when it finds a match. For example, if you define a function named MyFunction in two different classes, the Spreadsheet component will bind a reference to MyFunction to the first object added using the AddIn method. The Spreadsheet component also checks its own function library before looking at custom function libraries, so it is not possible to override any of the built-in functions.



Programming Microsoft Office 2000 Web Components
Programming Microsoft Office 2000 Web Components (Microsoft Progamming Series)
ISBN: 073560794X
EAN: 2147483647
Year: 1999
Pages: 111
Authors: Dave Stearns

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net