OO-Snippets: Call built-in functions

Commons

Keywordsbuilt-in function, function, min
LanguageOOBasic
ApplicationCalc
AuthorsKohei Yoshida (initial)
Paolo Mantovani
Supported Versions1.0.x  1.1.x  2.0.x  
Supported OSAll  
Question
Answer

To use Calc's built-in functions in Basic macro, you need to first create a service object of com.sun.star.sheet.FunctionAccess, and call the method "callFunction". Arguments are passed to this method as an array object even if there is only one argument. If the argument is a cell range, a cell range object must first be created, and passed into an array object before it is injected into the callFunction method (see the example code).

Code-Snippet-Listing (snippet-source)

Sub callFunction

       svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )

       ' Calculate min of numbers.
       arg = array( 10, 23, 5, 345 )
       print svc.callFunction( "MIN", arg )

       ' Calculate min of values in cell range A1:A17
       oSheet = ThisComponent.Sheets(0) ' Get leftmost sheet
       oCellRange = oSheet.getCellRangeByPosition( 0, 0, 0, 16 ) 'A1:A17
       arg = array( oCellRange )
       print svc.callFunction( "MIN", arg )

End Sub

Changelog

DateUserModification
2005-04-26koheiInitial version
2005-05-17paolomantovaniadded platform&version informations and auto-IDL linking

and