Function fnAverage() AS Long
Dim oFunctionAccess : oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
Dim sRange AS String : sRange = "$BL1DAT1_timing.$B$0:$F$0"
sRange = "B0:F0"
fnAverage = oFunctionAccess.CallFunction( "AVERAGE", sRange)
End Function
www.openoffice.org/api/docs XFunctionAccess wrote:::com::sun::star::table::XCellRange
for a SheetCellRange object that contains the data.
Dim oFunctionAccess As Object
Dim oSheet As Object, oRange As Object
oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
' get the first sheet of the document
oSheet = ThisComponent.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByPosition(1, 0, 5, 0) ' B1 to F1
'or oRange = oSheet.getCellRangeByName("B1:F1")
fnAverage = oFunctionAccess.CallFunction( "AVERAGE", oRange)
Function fnAverage(sSheet AS String, sRange AS String) AS Double
Dim oFunctionAccess : oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
Dim L(3) as long
L(0) = 10
L(2) = 20
L(3) = 30
fnAverage = oFunctionAccess.CallFunction( "AVERAGE", L)
End Function
n = fnAverage("BL1DAT1_timing", "B1:F1")
Function fnAverage(sSheet AS String, sRange AS String) AS Double
Dim oFunctionAccess : oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
Dim oDoc, oSheet, oRange AS Object
oDoc = ThisComponent
oSheet = oDoc.sheets.getByName(sSheet)
oRange = oSheet.getCellRangeByName(sRange)
fnAverage = oFunctionAccess.CallFunction( "AVERAGE", oRange)
End Function
this means the second parameter should be a CellRange, not a string that specifies a cell range.
Function fnAverage(oRange AS Object) AS Double
Dim oFunctionAccess : oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
arg = Array(oRange)
fnAverage = oFunctionAccess.CallFunction( "AVERAGE", arg)
End Function
Function fnAverage(sSheet AS String, sRange AS String) AS Double
Dim oFunctionAccess : oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
Dim oDoc, oSheet, oRange AS Object
oDoc = ThisComponent
oSheet = oDoc.sheets.getByName(sSheet)
oRange = oSheet.getCellRangeByName(sRange)
arg = Array(oRange)
fnAverage = oFunctionAccess.CallFunction( "AVERAGE", arg)
End Function
[Solved] How to call calc built in functions?
oCellRange = oSheet.getCellRangeByPosition(0,0, 0,3)
' the following fails (as we all know)
'dblValue = oFunctionAccess.CallFunction( "AVERAGE", oCellRange)
oDataArray = oCellRange.getDataArray()
' The next line will also fail
dblValue = oFunctionAccess.CallFunction( "AVERAGE", oDataArray)
args = Array(oDataArray)
' now it works !!
dblValue = oFunctionAccess.CallFunction( "AVERAGE", args)
|Variable | Value | Type
|--------------------------+---------+-----------------
|- oDataArray : : Object(0 to 3)
| - oDataArray(0) : : Variant(0 to 0)
| oDataArray(0)(0) : 10 : Variant/Double
| + oDataArray(1) : : Variant(0 to 0)
| + oDataArray(2) : : Variant(0 to 0)
| + oDataArray(3) : : Variant(0 to 0)
|--------------------------+---------+-----------------
|- args : : Variant(0 to 0)
| - args(0) : : Object(0 to 3)
| - args(0)(0) : : Variant(0 to 0)
| args(0)(0)(0) : 10 : Variant/Double
| + args(0)(1) : : Variant(0 to 0)
| + args(0)(2) : : Variant(0 to 0)
| + args(0)(3) : : Variant(0 to 0)
Return to OpenOffice Basic, Python, BeanShell, JavaScript
Users browsing this forum: No registered users and 1 guest