ExpressSpreadSheet: An Introduction
Purpose of this Article
This white paper provides an introduction to the ExpressSpreadSheet product (ESS).
The ESS product consists of native controls providing spreadsheet functionality for the following Borland IDEs:
- Delphi 4, 5, 6, 7
- C++ Builder 4, 5, 6
- Kylix 2.
The following topics are presented:
Overview
The most important thing I can say about the ExpressSpreadSheet product (ESS) is that it is a totally native control - it does not depend on other products either at design time or on deployed machines. Before you start worrying about using a non-standard solution, our developers have gone to great lengths to be compatible with MS Excel and the product does also support import/export from/to the latter's workbooks & worksheets (including its standard functions). There is more on this in Spreadsheet Compatibility below.
This product should not merely be viewed as a spreadsheet control, however. Having the ability to present a single cell or a collection of cells without headers or other adornments provides an advanced data entry engine (as shown by the flying demo).
Although the feature list is extremely comprehensive, there are a few things which are not supported in this release:
- Scripting
- Graphics
- Ability to reference items from other spreadsheet files.
The ESS architecture has been written from the ground up and we have been careful to use a modular extendible class hierarchy. The following screenshot (from the 'Class Structure' topic in the ESS help file) shows the class relationships after a workbook has been created:

Note, in particular, how functionality such as persistence, styles and formula handling have their own classes.
Feature List
Controls
ESS provides two components:

TcxSpreadSheetBook is basically a superset of TcxSpreadSheet to which further sheets may be added via the AddSheetPageMethod. The properties and events of the two components are very similar:
The highlighted properties above are not available for the basic TcxSpreadSheet component. Setting TcxSpreadSheetBook.CaptionBar to False makes both components look the same thus restricting worksheet selection to program control (setting either of the ActivePage or ActiveSheet public properties).
Functions
ESS contains many built-in functions which allow you to simplify formula construction. The latest list may be found in the help file via the 'Built-in Operators and Functions' topic. Functions provided include:
Type | Functions |
Operators | + - * / ^ |
Logical |
= <> < > <= >=
AND OR NOT IF
TRUE FALSE
ISBLANK ISNA ISNUMBER ISTEXT
|
Text |
& CONCATENATE
LEN LEFT RIGHT MID
UPPER LOWER TRIM FIXED DOLLAR
|
Arithmetic |
ABS INT MOD EVEN ODD SIGN TRUNC
ROUND ROUNDDOWN ROUNDUP
CEILING FLOOR RAND
SQR SQRT POWER INVRT
FACT EXP LN LOG LOG10
|
Geometric |
PI DEGREES RADIANS
SIN COS TAN ASIN ACOS ATAN
COSH ATAN2 ASINH ACOSH ATANH
|
Statistical |
MAX MIN
SUM SUMSQ
COUNT COUNTA COUNTBLANK
COUNTIF AVERAGE AVERAGEA
|
Date/Time |
NOW DATE TIME TODAY WEEKDAY
DAY MONTH YEAR
SECOND MINUTE HOUR
|
See the "Using built-in functions" in the ESS help for more details of how to use these functions.
As well as these built-in functions, ESS supports custom functions and these can even be provided by external dynamic link libraries. The procedures required for creating, registering and using custom functions are covered in great detail in the "Register Custom Functions" topic in the help file.
Cell/Row/Column Management
The comprehensive facilities include
- Sorting by column
- Unlimited columns and rows
- Insert/delete columns/rows
- Merge cells
- Hide/show columns/rows
- Named cells
-
Cell Style Management (covered in the next section - Format Cell dialog)
ESS provides safe merge/unmerge operations - after cells are unmerged, the styles and data they contained previously are completely restored, as illustrated below:
After formatting some cells:
| | After selecting a range and before Merge: |

| | 
|
After merge:
| | After unmerge:
|

| | 
|
The merge/unmerge operations are both performed via a call to ActiveSheet.SetMergeState. See the "Merge/Split Cells" topic for further information.
Other help topics within this area are:
- "Hiding a Row or a Column" - at runtime or via code
- "Working with Headers" - to change the width/height of any column/row within the active and any specified worksheet. You can also change the height/width of the column/row header panel and default width/height of columns/rows.
Cell Formatting
ExpressSpreadSheet provides excellent runtime cell formatting capability via a simple call to the FormatCells method. The following screenshot shows the syntax for applying to the selected cells of the active sheet:

This generates a popup dialog with four tabbed pages and provides the following runtime facilities:
- Cell Style
- Alignment
- Border
- Patterns
The Cell Style page enables you to set the cell text editing mask to a range of common formats as the following examples show:


The Alignment page provides access to horizontal & vertical alignment, wordwrap and the standard Font dialog for full control of text display:

The Border page allows you to set color and style of individual internal and external borders:

Finally, the Patterns page controls the background color of the selected cells:

As can be seen from the above screenshot, you have control over both colors used for the background pattern.
See the "Change Cell Style" and "About Cell Formatting" help topics for more information on cell formatting.
Spreadsheet Compatibility
ESS has been designed with MS Excel compatibility as a top priority and thus offers the following features:
- Import/Export from/to MS Excel 97/2000/XP without OLE or DDE
- XLS Formulas support
- RC reference style support
- MS Excel Format Cell support
- Same border styles and brushes as MS Excel
ESS allows you to load XLS files and save the data contained within them to XLS files, while maintaining the current visual presentation (cell data formats, cell styles, etc.). In addition, ESS provides the ability to save workbook contents to a stream (stream out) and then load this data from a stream to another workbook (stream back). See the "Export and Import Data" help topic for more details.
The 'Format Cells' dialog provides excellent runtime customization facilities for a cell or range of cells, as already shown in the Cell Formatting topic above.


There is also full horizontal and vertical alignment functionality:

See the "Change Cell Style" and "About Cell Formatting" help topics for more information on cell formatting.
Painting Styles
ESS provides you with two predefined painting styles
- Office 97 style
- Office XP style

In addition, you can implement your own custom styles via the TcxSheetPainter class. provides the following properties and methods which you can use or override:
- DrawCells method
- DrawHeaderBrick method
- DrawSelection method
- Canvas property
- HideSelection property
- ViewInfo property
See the "Perform Custom Painting" topic in the ESS help file, which shows the code required to produce the following effect:

Runtime customization
ESS provides you with the ability to manipulate cell data and its appearance at runtime without having to code manually (although you do have this option as well, of course):
- deleting or inserting cells
- merging and splitting cells
- formatting cells (similar to MS Excel)
- row heights and column widths (defaults and override individual items)
- hiding or unhiding columns and/or rows

See the "Managing Cells" and "Working with Headers" topics in the ESS help file for detailed descriptions and runtime code examples.
Undo/Redo Support
Any product providing data inputting facilities for the end user requires good undo/redo facilities, otherwise users will be very hesitant to use the product to its full potential - nobody enjoys having to repeat work because actions did not produce the expected result.
ESS undo/redo is not merely good - it is exceptional. All user modifications (including cell formating) are stored in undo & redo history lists and access is available by the user (Ctrl-Z & Alt-Z) or programmatically. In the latter case, it is possible to group actions into a complex action (see the StartComplexAction/EndComplexAction methods) which is undoable/redoable as if it were a single action. Thus, programmers can provide menu/toolbar items which change the look and feel of a complete sheet, for example, and the user can reverse it with a single Ctrl-Z (as, of course, he would expect).
It is easy too provide more control than Ctrl-Z/Alt-Z) by providing toolbar support as shown in the following screenshots:
Prior to the left screenshot above, I had entered data, done a bit of formatting and then I had pressed Ctrl-Z to undo the last data change, thus placing a single entry in the redo history list (and why both toolbar buttons are enabled). Clicking on the right portion of the Undo button displays the dropdown history list as shown above. As you select an item in the list by moving the mouse, all items above it remain selected automatically. Clicking OK undoes the five actions and, from the right screenshot, you can see that the actions have transferred to the redo list.
Thus, you are able to restore the file to any intermediate state at will. There is one caution though - if any new change is made, then the redo history is cleared.
ReportLink for ExpressPrinting System
Printing facilities at runtime are obviously very important for this type of control. ESS supplies a specialized ReportLink thus providing our ExpressPrinting System customers superb runtime customization facilities. Of particular note are:
- runtime choice of printing selected cells or the complete sheet
- control over how to print (or not) the spreadsheet adornments (headers etc.)
The following screenshot shows an MS Excel demo spreadsheet loaded into a TcxSpreadSheetBook via its LoadFromFile method:

After highlighting a block of cells, the ExpressPrinting System's TdxComponentPrinter.Preview was invoked by clicking on the Preview button. Various changes were made (all at runtime - XLS file was unaltered) so that the Preview displayed the following:

Developers already using the ExpressPrinting System with one or more of our other products will instantly realize what they can provide for their customers - with no learning curve!
ESS is the perfect kind of product for the EspressPrinting System type of solution, as end-users will often require to customize their print output and/or print just a block of cells. Having learned how to do this with one product, I cannot resist suggesting that you might like this kind of solution for printing other types of control as well.
Demos
ESS ships with four demo applications for each of the three supported platforms: Delphi, CBuilder & Kylix:
Customers with our ExpressPrinting System product have another demo provided. The SpreadSheetRL demo (placed with the other ReportLink demos) is based upon the Stocks demo above.
As well as the demos themselves, a demo.xls file is shipped to show some of the functionality available from the product:


FeaturesDemo
This is the main demo which shows how to provide the main facilities available by using toolbars and/or menus:


This is actually an MDI application and shows how to open multiple spreadsheets. The FeatureChild form contains the spreadsheet control and an instance of it is loaded when the application executes. In order to find the particular functionality you require, the easiest route is via the Categories of the ActionList component:


StocksDemo
The demo is provided in order to show pre-loading of data and style manipulation by program:


Of particular note are the supplied helper methods for accessing cells and handling selected areas. For example, much use is made of SetCellText for loading values into cells, e.g.:

The SetCellText method is very simple:

Note how setting the ActivePage property allows us to use a generic routine to update different sheets. The GetCellObject method is particularly important and provides access to individual cells and their properties. As it returns an object instance, it is essential that it is freed after use in order to avoid memory leaks.
FlyingDemo
One of the major advantages of ESS over a traditional spreadsheet is the ability to embed it into a form and interact with other controls, thus providing a powerful data entry engine. This demo provides an excellent example of this type of use:


In the UK, before any light aircraft is permitted to fly, the pilot has to get a manifest approved proving that the plane has sufficient fuel for the proposed flight and that it is always stable (i.e. the center of gravity is always within the permitted envelope). The screenshot above shows a spreadsheet, a plane image and a drawn chart. Changing the values of the white cells in the spreadsheet changes the calculations and re-draws the chart. For example, look at the effect of the two front seat passengers weighing 400lbs instead of 250:


Note that the plane is only just unstable (by being front heavy) and burning off fuel during the flight reduces the weight sufficiently for stability. Incidentally, adding 20lbs of ballast in the baggage compartment is all that is needed to have a stable flight.
CustomFunctionDemo
Although we provide a great many functions 'out of the box', it is impossible to provide all that are needed now or in the future. ESS, therefore, provides facilities for custom functions and this simple demo shows how to implement an 'Area' function. The demo provides a simple test harness, but the real interest is in the AreaCustomFunc unit:

In particular note how the AreaFunc method is registered and how it makes use of the EnumParamValues method. The AreaFuncCallBack method is called by the latter once for every parameter. As you can see, the parameter currently being processed by each callback is available via Sender.CallBackIndex.
See "Register Custom Functions" topic in the help file for more information.
Summary
This paper has presented an introduction to the ExpressSpreadSheet product. The significant points covered include:
- a native solution
- compatibility with MS Excel
- many built in functions plus custom function support
- safe cell merge and unmerge
- extensive cell/row/column formatting facilities
- Office 97 & XP styles plus custom style support
- superb undo/redo support
- ReportLink for ExpressPrinting System for end-user report customization
Finally, you will find a lot more information in the ESS help file and it is particularly worth looking at the Task Based help section.