Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Excel add in development in C++ Aplications in finance - Dalton S.

Dalton S. Excel add in development in C++ Aplications in finance - Wiley publishing , 2005. - 425 p.
ISBN 0-470-02469-0
Download (direct link): exceladdindevelopmentincand2005.pdf
Previous << 1 .. 92 93 94 95 96 97 < 98 > 99 100 101 102 103 104 .. 168 >> Next

reference xloper.
Enumeration value: 147 (x93)
Enumeration value: Callable from: Return type: Arguments:
236
Excel Add-in Development in C/C++
Callable from: Commands and macro sheet functions.
Return type: An xltypeRef xloper.
Arguments: 1: ReferenceStr: Text string containing the input cell reference
2: A1Style: (Optional.) Boolean. True indicates that the given reference is in A1 style. False or omitted indicates R1C1 style.
The Excel4() function set-up and call are as shown in the following C/C++ code example of an exportable function that wraps up the call to xlfTextref. Note that the Boolean argument is passed as a pointer to a constant xloper.
xloper * stdcall text_ref(char *p_ref, int A1_style)
{
cpp_xloper Arg1(p_ref); cpp_xloper RetVal;
Excel4(xlfTextref, &RetVal, 2, &Arg1,
A1_style ? p_xlTrue : p_xlFalse);
// Extract and return xloper. Arg=true to ensure Excel frees memory return RetVal.ExtractXloper(true);
}
Note: The reference as text must not have a leading *=’. For example, the function xlfGetName returns the address of a given named range but includes a leading ‘=’ that should be removed before it can be converted to a range xloper using xlfTextRef.
8.9.16 Converting a reference to text: xlfReftext
Overview: This function converts a cell reference to a string xloper of
the form [Book1.xls]Sheet1! R1C1.
Enumeration value: 146 (x92)
Callable from: Commands and macro sheet functions.
Return type: Text string.
Arguments: 1: Reference: A reference xloper (xltypeSRef or
xltypeRef).
2: A1Style: (Optional.) Boolean. True requests that the
returned text is in A1 style. False or omitted requests R1C1 style.
This function is useful when, for example, converting a reference to an R1C1 style string to be passed to the xlfGetDef function, which returns the defined name (if it exists) associated with the original reference. (See section 8.10 Working with Excel names on page 239.) This function is used for this purpose in the example project in the code of the xlName class. The function xlfGetCell, argument=1, also returns an address string but only in A1 style.
Accessing Excel Functionality Using the C API
237
The Excel4() function set-up and call are as shown in the following C/C++ code example of an exportable function that wraps up the call to xlfReftext.
xloper * stdcall ref_text(xloper *p_ref, int A1_style)
{
cpp_xloper Arg2(A1_style != 0); cpp_xloper RetVal;
Excel4(xlfReftext, &RetVal, 2, p_ref, &Arg2);
// Extract and return xloper. Arg=true to ensure Excel frees memory return RetVal.ExtractXloper(true);
}
8.9.17 Information about the calling cell or object: xlfCaller
Overview: Returns information about what originally initiated this call
into the DLL. It can be called many times in the same call and
will return the same information every time.
Enumeration value: 89 (x59)
Callable from: Commands, worksheet and macro sheet functions.
Return type: Various depending on the how the DLL was called. (See
Table 8.19.)
Arguments: None.
Table 8.19 Return types and information for xlfCaller
Where the DLL was called from: What xlfCaller returns:
A single cell on a worksheet. A single-cell xltypeSRef or xltypeRef xloper of that cell.
A multi-cell array formula on a worksheet. A multi-cell xltypeSRef or xltypeRef xloper.
A command on a menu bar A horizontal 3-element array: • the command’s position number • the menu number • the menu bar number
A command attached to a toolbar A horizontal 2-element array: • the command’s position number • the command bar name
A command attached to a control object The object’s ID
A trapped data entry or double-click event on a worksheet A single-cell xltypeSRef or xltypeRef xloper of the affected cell or range of cells.
Others #REF!
238
Excel Add-in Development in C/C++
Note: xlfCaller can sometimes return an xloper that has had memory allocated by Excel. When the xloper is done with, the memory must be freed by Excel. (See section 7.3, Getting Excel to free memory allocated by Excel for details.)
Warning: The DLL can be called by the operating system, for example, DllMain () or during a Windows call-back. Calling xlfCaller in these contexts is not necessary and may have strange and undesirable consequences.
Note that some of Excel’s built-in functions behave differently when called from a single cell or a number of cells in an array formula. This kind of behaviour can be replicated in DLL functions by detecting the type of the caller, and the size if it is a range. (See section 2.6.8 Conversion of multi-cell range references on page 14 for more detail.) You can also use the xlfGetCell function, with argument 49, to detect if a given cell reference is part of an array.
Apart from the usefulness of this function in determining the type of caller, it plays an important role in the naming and tracking of cells that are performing some important task. See section 8.10 immediately below and sections 9.7 to 9.10. It also can play an important role in returning the pre-call value of the calling cell. This can be useful in stopping the propagation of errors as the following simple function demonstrates:
Previous << 1 .. 92 93 94 95 96 97 < 98 > 99 100 101 102 103 104 .. 168 >> Next