Page 1 of 1

[Solved] Call nested Calc function in Basic

Posted: Thu Jan 30, 2025 11:55 am
by luofeiyu
The formula can get rigth value in openoffice calc.

Code: Select all

=INDEX(B1:B47,MATCH("land",A1:A47,0))
I want to write it in oobasic codes:

Code: Select all

sub callindex()
    dim oFunAccess as object
    oFunAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
    dim oDoc, oSheet, oRange as object
    
    oDoc = ThisComponent
    oSheet = oDoc.sheets.getByName("Sheet1")
    oRange = oSheet.getCellRangeByName("a1:a47")	
    dim embedded_formula as string    
    embedded_formula = "MATCH('land',A1:A47,0)"
    num = oFunAccess.CallFunction( "index",array("b1:b47", embedded_formula))
    print num
end sub
https://i.sstatic.net/L5ie9wdr.png

Re: How call worksheet function with embedded worksheet function?

Posted: Thu Jan 30, 2025 1:48 pm
by karolus
Hallo

obviously its:

Code: Select all

sub call_nested_calc()
    oFunAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
    
    oDoc = ThisComponent
    oSheet = oDoc.sheets.getByName("Sheet1")
    with oSheet
    	a_Range = .getCellRangeByName("a1:a47")
    	b_Range = .getCellRangeByName("b1:b47")
    end with	
    with oFunAccess
    	num = .CallFunction( "index",array( b_Range, .CallFunction("match", array("land", a_Range, 0))))
    end with
    print num
end sub