I recently learned that you can use Inline Array Constants in calcfunctions, e.g.
=DGET(databaseRange;selectioncolumn;{"key";"test"})
I’m now trying to use DGET from within a custom libreoffice-basic macro function, however I can’t figure out how I can write my macro function, so that it also accepts an Inline array constant (e.g. {“key”;“test”})
The function I currently got (this is a test function, that I extracted from all the other code I got):
Function TestF(whatAmI As Object)
Dim oDoc 'References ThisComponent with a shorter name.
oDoc = ThisComponent
Dim oRangeDatabase 'DatabaseRange object.
Dim dataArea As Object
If NOT oDoc.DatabaseRanges.hasByName("MyDatabase") Then
Exit Function
End If
oRangeDatabase = oDoc.DatabaseRanges.getByName("MySelect")
dataArea = ScDatabaseRangeObj2ScCellRangeObj(oRangeDatabase)
Dim oRangeSelectionCell 'DatabaseRange object.
Dim selectorCell As Object
If NOT oDoc.DatabaseRanges.hasByName("MySelectionCell") Then
Exit Function
End If
oRangeSelectionCell = oDoc.DatabaseRanges.getByName("MySelectionCell")
selectorCell = ScDatabaseRangeObj2ScCellObj(oRangeSelectionCell)
Dim MyArr(1 to 2, 1 to 1) As Variant
MyArr(1, 1) = "key"
MyArr(2, 1) = "test"
Dim oService As Object
Set oService = createUnoService("com.sun.star.sheet.FunctionAccess")
Dim T
' Signature of Array: ScCellRangeObj, ScCellObj, ScCellRangeObj
REM Now I tried a bunch of ways, but all failed:
TestF = oService.callFunction("DGET", Array(dataArea, selectorCell, whatAmI))
TestF = oService.callFunction("DGET", Array(dataArea, selectorCell, {"key";"test"}))
TestF = oService.callFunction("DGET", Array(dataArea, selectorCell, MyArr))
End Function
I try to call this like so:
=TestF({"key";"test"})
But all ways I tried fail with an InvalidArgumentException. Due to some tests I can say that this is caused by the last parameter, that I’d like to pass as an Inline Array Constant, however I cna’t figure out how to use such an Inline Array Constant (that gets passed to the function as Variant(1 to 2, 1 to 1) ) in the callFunction() call.
I’d be very glad if anyone has any ideas, or could explain to me how libreoffice handles Inline Array Constants within their own functions.
Thank you very much.