Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

14.3 Cells and Ranges

Objective Grid accepts several basic types of cell entries: text, constant numeric values, dates, time, formulas that calculate a value, and graphs. Calculated values can be single numbers, strings, arrays, or tables of values.

14.3.1 Text Cell Values

Text entries are useful for:

14.3.1.1 Entering Text

A text entry is usually used for descriptive information such as a column heading, a row label, or an explanatory comment. You can also make text entries of names, addresses, or other non-numeric information. Objective Grid treats text and numeric entries differently, so you can differentiate between text and numeric values when entering cell contents.

To enter most text into a cell, just type the text string as you want it to appear or programmatically call SetExpressionRowCol(). If the text you wish to enter would normally be considered a formula, then you must precede the actual text with the ' (apostrophe) character.

If you make an entry that is not text but which returns an error when treated as a formula, Objective Grid displays an error message. Section 14.8.2, "Error Messages Reference," contains an alphabetized summary of error messages.

14.3.1.2 Treating Numeric or Date Entries as Text

Note that some numeric entries, such as phone numbers, should really be treated as text. For example, if you enter the phone number 555-1212 in a cell, Objective Grid displays the number -657, the difference of 555 and 1,212. However, if you start the string with the apostrophe ('555-1212, for example), Objective Grid treats the phone number as text and does not calculate it.

14.3.1.3 Entering Special Characters

Special characters can be entered as text by using the back-slash convention (\). (This technique is compatible with ANSI C escape codes.) The most common use of this is to force explicitly a new line in a text cell by entering \n. Other useful ones are \" which allows the double quote character within a string and \\ which allows the back-slash character.

14.3.2 Numeric Values

If a cell entry begins with a digit (from 0 to 9), Objective Grid treats the entry as a numeric entry.

Objective Grid also recognizes the following symbols as indicators of numeric entries: ., +, and -. You can format numeric values to be displayed in several ways, including fixed formats, scientific notation, currency, and hexadecimal.

14.3.2.1 Entering Numeric Values

Follow these conventions for entering numeric values:

14.3.2.2 Changing the Numeric Format

You can choose from a variety of formats for displaying numbers. The display formats do not change the number itself, the way the number is stored internally, or the way it is used in calculations. Formatting just changes the way Objective Grid displays numbers.

See Section 5.14, "Number Formatting," for information on using the CGXStyle::SetFormat() API. The end-user might change the number formatting with the CGXStyleSheet dialog.

14.3.3 Dates and Times

Objective Grid provides special, built-in features for displaying date entries in the format you choose. Date and time formats include: 24-Oct-99, 24-Oct, 10/24, Oct-99, 10/24/99, 24.10.1999, and 1999-10-24 (ISO 8061). Time is displayed as: 12:00:05.

14.3.3.1 Entering Date and Time Values

If you entered a date or time as a string of numbers separated by hyphens, (for example, 10-31-99) Objective Grid would interpret this string, store a date value in the cell and then set the cell format to date.

If the year (yy) is omitted when entering a date into a cell, the current year is assumed. For example, entering /7/17 is equivalent to entering /7/17/01 when the current year is 2001.

Objective Grid internally stores date and time information using the same convention as other popular spreadsheet programs: Dates are represented as an integer equal to the number of days since December 31, 1899. Times are represented as fractions of a day, starting at midnight. For example, 6:00 AM is stored as 0.25 (a quarter of a 24-hour day). Using this convention, date and time values may be used together. For example, the date/time value 1.25 corresponds to 6:00:00 AM, January 1, 1900.

You can use date values in calculations. For example, subtracting 05-Oct-99 from 10-Oct-99 yields a value of 5 days.

14.3.4 Formulas

Formulas establish and calculate mathematical relationships between elements of the spreadsheet.

Objective Grid formulas can calculate with numbers, text, logical values, cell references, and other formulas. For example, you can easily calculate the sum of a series of cells, the total of values in a column, or the absolute value of another cell entry.

14.3.4.1 Entering Formulas

Formulas are the heart of the Objective Grid spreadsheet, defining relationships between the values in other cells. For example, formulas can be used to sum a column of numbers, compute an average, determine a minimum or maximum value, or round the results of a calculation.

While constant entries remain the same until you change them, cells defined by formulas are automatically changed to reflect changes in referenced cells— even when there are complex interdependencies among cells.

Once entered in a cell, formulas are hidden behind the scenes, performing their work in the background and displaying only the result of their calculation. To view the formula in a cell, move the cell cursor to the cell and switch the cell into edit mode. You can edit the formula or values within the cell.

See also Section 14.1.9, "Display Formula Expression in Cells."

14.3.5 Built-in Functions

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, no 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 itself 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 application's 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:

CMyWorksheetFunctions is the class that you derived from CGXWorksheetFunctions.


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\grid\engine\fnmath.cpp) for examples of how to implement worksheet functions.

14.3.5.1 Tips

When writing functions you can get a pointer to the sheet context, to the CGXFormulaSheet, and to the CGXGridCore object using the following methods:

14.3.6 Ranges

A range is a contiguous, rectangular block of cells that has been referenced as a group in a cell formula or selected to be affected by some editing action, such as Copy Formulas or Move.

14.3.6.1 Creating a Range Object

A range object can either be initialized as an empty range, initialized with another range, or specified by coordinates. These examples show some alternatives for creating a range object.

14.3.6.2 Named Ranges

Individual cells and cell ranges may be referred to by their standard address coordinates (A5..D25, for example) or by pre-assigned names. The Named Range option lets you assign a name to any cell or cell range.

A named range is a range of cells to which a name has been assigned with the Named Range utility. A named cell is a cell to which a name has been assigned. Both named ranges and named cells can be referenced by their names or by their addresses.

Using names can help clarify the logic of your spreadsheet, making it easier to share among users, and easier to update long after it was originally designed. Once defined, names can be used anywhere standard cell or range references are used, including in cell formulas.

The following guidelines apply to named ranges:

14.3.7 Copying and Moving Cells

14.3.7.1 Copying Formulas

The Copy operations, clipboard copy and OLE Drag-and-Drop, duplicate a cell or range of cells in addition to all the formatting and then place these formulas in a new location, overwriting existing data in the destination range. Objective Grid automatically translates relative cell references in the copied formulas to reflect their new locations. For example, if cell A10 contained the formula =@SUM(A1..A9) and you copied it to cell B10, then B10 would contain the formula =@SUM(B1..B9).

To create an absolute cell reference, which is a value that Objective Grid doesn't translate if the cell contents are copied or moved, insert a dollar sign ( $ ) before each component of the cell reference (e.g., $A$1). For more information, refer to Section 14.5.2, "Formula Values," and Section 14.5.5, "Cell Referencing in Objective Grid."

Use the CopyCells() method to perform a copy operation programmatically.

Objective Grid overwrites any existing data in destination ranges, so plan carefully before carrying out Copy and Move operations. If you overwrite data by mistake during a Copy or Move, you can put it back like it was using Undo.

14.3.7.2 Moving Data

The Move operation moves a cell or range of cells to a new location, along with all formulas. Objective Grid clears the source cells and overwrites any existing data in the destination cells. Like the Copy Formulas operation, all cell references are updated to reflect the new cell/range location.

Use the MoveCells() method to perform a move operation programmatically.

The effects of moving cells include:

14.3.7.3 Deleting Rows and Columns

If you delete a row or column that contains a cell that is referenced by a formula in another cell, the formula reference will not be modified. Range references will be updated when rows or columns are deleted within a range specification.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.