class CGXWorksheetFunctions: public CObject
The Objective Grid Formula Engine comes with over 240 built-in worksheet functions. Functions can be used alone or in combination with formulas and other functions. Objective Grid was designed for demanding users, so it provides many highly specialized functions for business, engineering, scientific, and statistical applications. Sometimes you might want to provide only a subset of these worksheet functions to the end-user, none worksheet functions at all, or add your own worksheet functions.
The CGXWorksheetFunctions class provides an extensible interface to the formula engine where you specify what worksheet functions should get linked into your application and where you can also add your own custom worksheet functions to the engine.
CGXWorksheetFunctions itsself implements no worksheet functions. This makes sure that none of the built-in functions will be linked into your executable and waste disk space unless you really need them.
In order to enable all built-in functions, you should call
GXEnableWorksheetFunctions();
from your applications InitInstance method. GXEnableWorksheetFunctions instantiates the CGXDefaultWorksheetFunctions class. This class has a lookup table with all built-in worksheet functions.
If you want to add your custom functions, you should subclass CGXWorksheetFunctions (or CGXDefaultWorksheetFunctions) and override LookupFunction. In your InitInstance method you can register your class with
GXGetEngineState()->SetWorksheetFunctionClass(new CMyWorksheetFunctions);
whereas CMyWorksheetFunctions is the class that you did derive from CGXWorksheetFunctions.
Note:
Implementing your own custom worksheet functions is only recommended for advanced users. When implementing your own custom worksheet functions you will have to deal directly with the formula engine code which is not documented at all. Take a look at the existing worksheet functions (e.g. in src\engine\fnmath.cpp) for examples how to implement worksheet functions.
Some tips:
When writing functions you can get a pointer to the sheet context, to the CGXFormulaSheet and to the CGXGridCore object with the following methods:
Based from the sheet context id (typically called si when passed to a C-Function) you can get a pointer to the _gx_sheet_context object with
gxSheetContext * context = _gx_get_context_ptr(si);
Based on this context you can get a pointer to the associated CGXFormulaSheet by calling
CGXFormulaSheet* pSheet = context->m_pSheetContext;
Now you can also get a pointer to an associated CGXGridCore object by calling
CGXGridCore* pGrid = pSheet()->Grid();
Now you can call pGrid->GetStyleRowCol and any other grid functions.
#include <gxall.h>
See Also
CGXDefaultWorksheetFunctions GXEnableWorksheetFunctions