There is some way to nest various calc functions creating the Service (?)
com.sun.star.sheet.FunctionAccess
The code below is what I’m trying to do.
Sub Test1
Dim oDoc as Object, SpreadSheet as Object, targetCell as Object
Dim nRow as Long
oDoc = ThisComponent
SpreadSheet = oDoc.getSheets().getByIndex(0)
'For nRow = 2 To fnLastRow
'targetCell = SpreadSheet.getCellByPosition(2, nRow-1)
'targetCell.setFormula("=RIGHT(A" & nRow & ";" & _
' "LEN(A" & nRow & ")-" & _
' "SEARCH(" & CHR$(34) & "Residência" & CHR$(34) & _
' ";" & "A" & nRow & ")-11)" )
' Next nRow
oRange = SpreadSheet.getCellByPosition(1, 1)
oRange.setString ( fnNestFormulas( SpreadSheet.getCellRangeByName("A2"), "Residência") )
End Sub
rem------------------------------------------------------------------------------
Function fnNestFormulas (oCell$, sWord$)
Dim oDoc as Object : oDoc = ThisComponent
Dim oSheet as Object, oService as Object
Dim Personal_Address
oSheet = oDoc.getCurrentController.getActiveSheet()
oService = CreateUnoService("com.sun.star.sheet.FunctionAccess")
Personal_Address = oService.callFunction("RIGHT", _
array(oSheet.getCellRangeByName(oCell), _
"LEN", oSheet.getCellRangeByName(oCell) & - _
"SEARCH", array(sWord, oSheet.getCellRangeByName(oCell) ) _
& -11 ) )
fnNestFormulas = Personal_Address
End Function
rem------------------------------------------------------------------------------
Function fnLastRow
Dim oDoc as Object : oDoc = ThisComponent
Dim oSheet as Object, oService as Object, i as Variant
oSheet = oDoc.getCurrentController.getActiveSheet()
oService = CreateUnoService("com.sun.star.sheet.FunctionAccess")
i = oService.callFunction("COUNTA" , _
array(oSheet.getCellRangeByName("A:A")))
fnLastRow = i
End Function 'fnLastRow
File Example:
FileExample.ods (26,4,KB)
I would appreciate if someone tells me what I’m doing wrong on the code, or if what I’m asking for is impossible.