Cell B2 on The KEYVALUE function
sheet of the example workbook contains a formula calling the
function KEYVALUE
:
=KEYVALUE("Triangle";B3:C6)
This function call is meant to build a triangle.
We can see that cells with dark blue background in the sheet
contain formulas calling KEYVALUE
to build polygons
and to calculate their areas.
There are no functions such as BuildPolygon
,
CalculateArea
or anything similar. Indeed,
independently on the core-library,
KEYVALUE
[2]is the only function exported to OpenOffice Calc.
This is not as odd as it might seem (one could expect to call
different functions for different tasks). Even when calling a specific
function for a precise task, the function might change its behaviour
depending on the data it receives. For instance, a function
CreatePolygon
would create a triangle or a square
(or whatever) depending on the number of sides given. KeyValue goes one
step further and considers the choice of the task as part of the input
data as well.
Alternatively, we can think that KEYVALUE
does have one single task: It creates data sets
. A data set is a collection of data organized in key-value
pairs (recall the stock prices example given in Section 1). The example above creates a data set called
Triangle containing key-value pairs defined by the
array B3:C6 (more details to follow). Analogously,
the formula in cell E2
=KEYVALUE("Square";E3:F6)
creates a data set called Square containing key-value pairs defined by array E3:F6.
More generally, KEYVALUE
's first parameter is
the name of the data set to be created. This is a compulsory parameter
of text type (which might be left empty ""
for anonymous data sets). Moreover, as for those
examples, often the data set name is the result returned from
KEYVALUE
to OpenOffice Calc.
Once created, a named data set is stored in a repository and might be retrieved latter through its name.
Other KEYVALUE
's parameters are optional and
define key-value pairs following patterns discussed in next
section.