Function Handling

From Apache OpenOffice Wiki
Jump to: navigation, search

This section describes the services which handle spreadsheet functions.

Calculating Function Results

The service calls any spreadsheet function and gets its result without having to insert a formula into a spreadsheet document.


The service can be instantiated through the service manager. The interface contains only one method, callFunction(). The first parameter is the name of the function to call. The name has to be the function's programmatic name.

  • For a built-in function, the English name is always used, regardless of the application's UI language.
  • For an add-in function, the complete internal name that is the add-in component's service name, followed by a dot and the function's name as defined in the interface. For the getIncremented function in the example from the add-in section, this would be: "".

The second parameter to callFunction() is a sequence containing the function arguments. The supported types for each argument are described in the interface description, and are similar to the argument types for add-in functions. The following example passes two arguments to the ZTEST function, an array of values and a single value.

// --- Calculate a function ---
  Object aFuncInst = xServiceManager.createInstance(""); xFuncAcc = (
      UnoRuntime.queryInterface(, aFuncInst);
  // put the data into a two-dimensional array
  double[][] aData = {{1.0, 2.0, 3.0}};
  // construct the array of function arguments
  Object[] aArgs = { aData, new Double( 2.0 ) };
  Object aResult = xFuncAcc.callFunction("ZTEST", aArgs);
  System.out.println("ZTEST result for data {1,2,3} and value 2 is "
      + ((Double)aResult).doubleValue());

In Calc, an argument of the function may accept a range of cells, e.g =SUM(B12:G55). When calling a spreadsheet function, a range argument is transmitted as an array with two dimensions. The first corresponds to the row, the second corresponds to the column, indexes are zero-based.

Documentation note.png The implementation of uses the same internal structures as a spreadsheet document, therefore it is bound by the same limitations, such as the limit of rows and columns for the function arguments. Version 3.3 of supports 1048576 rows and 1024 columns.

Information about Functions

The services and provide help texts about the available spreadsheet cell functions, including add-in functions and their arguments. This is the same information that API Calc displays in the function AutoPilot.


The service is instantiated through the service manager. It provides three different methods to access the information for the different functions:

The that is returned by any of these calls is a sequence of structs. To access one of these properties, loop through the sequence, looking for the desired property's name in the Name member. The Arguments property contains a sequence of structs, one for each argument that the function accepts. The struct contains the name and description of the argument, as well as a boolean flag showing if the argument is optional.

Documentation note.png All of the strings contained in the service are to be used in user interaction, and therefore translated to the application's UI language. They cannot be used where programmatic function names are expected, for example, the service.

The Recently Used Functions section below provides an example on how to use the service.

Recently Used Functions

The service provides access to the list of recently used functions of the spreadsheet application, that is displayed in the AutoPilot:Functions and the Function List window for example.


The service can be instantiated through the service manager. The interface's getRecentFunctionIds() method returns a sequence of function identifiers that are used with the service. The setRecentFunctionIds() method changes the list. If the parameter to the setRecentFunctionIds() call contains more entries than the application handles, only the first entries are used. The maximum size of the list of recently used functions, currently 10, can be queried with the getMaxRecentFunctions() method.

The following example demonstrates the use of the and services.

  // --- Get the list of recently used functions ---
  Object aRecInst = xServiceManager.createInstance(""); xRecFunc = (
      UnoRuntime.queryInterface(, aRecInst);
  int[] nRecentIds = xRecFunc.getRecentFunctionIds();
  // --- Get the names for these functions ---
  Object aDescInst = xServiceManager.createInstance(""); xFuncDesc = (
      UnoRuntime.queryInterface(, aDescInst);
  System.out.print("Recently used functions: ");
  for (int nFunction=0; nFunction<nRecentIds.length; nFunction++) {[] aProperties = xFuncDesc.getById(nRecentIds[nFunction]);
      for (int nProp=0; nProp<aProperties.length; nProp++)
          if (aProperties[nProp].Name.equals("Name"))
              System.out.print(aProperties[nProp].Value + " ");
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages