- How to?
- Position of calculation row
- Customizing the calculation row
- Deleting the custom calculation rows
- Exporting the results of calculations
- Export via the AAF (Automatic Application Features) of Table control
- Export via the WLanguage functions
Programming custom calculations in Table controls (prefix syntax)
WINDEV allows you to easily insert automatic calculations into the columns found in the Table and TreeView Table controls.
From version 22, you also have the ability to perform automatic calculations in the columns found in the Table and TreeView Table controls. These calculations are performed through programming.
To add a custom calculation in the column of a Table control (or TreeView Table), use <Table>.FormulaAdd
This function expects as parameter:
- the name of the column taken into account for the calculation.
- the caption of the row that displays the calculation in the Table control. If this caption does not exist, the row will be created. If this caption exists, the calculation will be displayed in the requested column.
- the name of three procedures. These procedures are used to:
- initialize the calculation,
- to perform a calculation for each row of the Table control,
- perform the final calculation if necessary.
nRow is int
nRow = TABLE_MyTable.COL_Num.FormulaAdd("Positive mean", ProcInit, ProcAdd, ProcEnd)
// Change the background color of the row for custom calculation
COL_Num[nRow].BackgroundColor = LightRed
nCounter is int
INTERNAL PROCEDURE ProcInit()
nCounter = 0
INTERNAL PROCEDURE ProcAdd(Accumulator, ColValue)
// Ignores the negative numbers or NULL
IF (ColValue <= 0) RESULT Accumulator
RESULT Accumulator + ColValue
INTERNAL PROCEDURE ProcEnd(Accumulator)
IF nCounter = 0 THEN RESULT 0
// Calculate the mean
- The custom calculation rows are automatically recalculated as soon as the content of the Table or TreeView Table control changes.
Tip: The iteration procedure is called for each row: we advise you not to perform slow calculations (avoid the accesses to the database for example).
- The TotalsEnabled property does not allow or forces automatic or custom calculations in a Table control.
- If the DisplayEnabled property is used on the Table control and is set to False, the column calculations are not updated.
- The following syntax is used to retrieve the value of the custom calculation for a column:
where <Row number> is the row index returned by <Table>.FormulaAdd.
<Table control>.<Column name>[Row number]
Position of calculation row
To configure the position of automatic or custom column calculations:
- Go to the "General" tab of the Table control (to do so, select the name of the Table control and click "General").
- Specify the location of totals. To display the results:
- in one or more rows directly added after the last control row, check "In the table, after the last row".
These rows are visible:
- at the bottom of the Table control if the control includes no vertical scrollbar.
- when the vertical scrollbar is located at the very bottom if the Table control includes a vertical scrollbar.
- below the Table control, check "Below the table".
These rows are always visible.
- you also have the ability to perform column calculations without displaying them ("No display" option).
- Validate the Table control description window.
Customizing the calculation row
You have the ability to customize (caption, color, font, height, ...):
- the added row by using the following syntax:
<Table control>[Row number].<Property> = <New value>
- the cell containing the result by using the following syntax:
<Table control>.<Column name>[Row number].<Property> = <New value>
Caution: the first column contains the caption of the calculation if it exists.
- <Row number> is the row index returned by <Table>.FormulaAdd.
- <Property> can correspond to one of the following properties:
|BackgroundColor||Used to find out and modify the background color of a calculation cell.|
|Caption||Used to find out and modify the caption of the row containing a calculation cell.|
|Color||Used to find out and modify the color of the text displayed in a calculation cell.|
|Font||Allows you to find out and modify the font used in a calculation cell.|
|FontBold||Used to find out and modify the "Bold" attribute for the column elements.|
|FontCondensed||Used to find out whether the characters of column elements are condensed or not, and to condense (or not) the characters of column elements.|
|FontExtended||Used to find out whether the characters of column elements are extended or not, and to extend (or not) the characters of column elements.|
|FontItalic||Used to find out and modify the "Italic" attribute for the column elements.|
|FontLarge||Used to find out whether the characters of column elements are enlarged or not, and to enlarge (or not) the characters of column elements.|
|FontName||Used to find out and modify the font used for the column elements.|
|FontSize||Used to find out and modify the size of the font used for the column elements.|
|FontStrikeOut||Used to find out and modify the "StrikeOut" attribute for a calculation cell.|
|FontUnderlined||Used to find out and modify the "Underline" attribute for the column elements.|
|Height||Used to find out and modify the height of a calculation cell.|
|Name||Used to find out the name of a calculation cell.|
|Note||Used to find out and modify the notes associated with a calculation cell.|
|State||Gets and changes the display state of the row containing the calculation cell.|
|Visible||Used to find out whether a column is visible and to make a column visible/invisible.|
|Width||Used to find out and modify the width of a calculation cell.|
Deleting the custom calculation rows
Exporting the results of calculations
Export via the AAF (Automatic Application Features) of Table control
The context menu of Table and TreeView Table controls contains several options to export the control content.
During this export, the results of custom calculations are exported.
Remark: Only the value is exported, not the caption.
Export via the WLanguage functions
Several WLanguage functions can be used to export the content of a Table control in a specific format (Word, Excel, XML, ...). During this export, the rows corresponding to calculations are also exported by default.
To avoid exporting the calculation rows, all you have to do is specify the taNoTotal
constant in the following functions:
|TableToExcel||Creates an Excel file with the data from a Table or TreeView Table control.|
|<Table>.ToClipboard||Copies the content of a Table or TreeView Table control to the clipboard.|
|<Table>.ToText||Creates a character string from the data found in a Table or TreeView Table control.|
|<Table>.ToWord||Creates a Word file (.RTF) from the data found in a Table or TreeView Table control.|
|<Table>.ToXML||Creates an XML file from the data found in a Table or TreeView Table control.|