Bug 60158

Summary: python cannot invoke LO cacle built-in functions
Product: LibreOffice Reporter: jmxhyz <jmxhyz>
Component: BASICAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: medium CC: jmadero.dev
Version: 4.0.0.2 rc   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: This document is embedded python script.

Description jmxhyz 2013-02-01 13:20:34 UTC
Created attachment 74049 [details]
This document is embedded python script.

Trying with python to invoke cacle built-in functions,
However, it seems the cacle built-in functions can only accept python tuple,
it can not accept python list.
If the built-in functions with multiple parameters, I do not know how to pass parameters?

The following invokeSUM function run successfully, error while invokeCOUNTIF.

# python code list
# -*- encoding: UTF-8 -*-

import uno
import unohelper
from com.sun.star.script.provider import XScriptProviderFactory
from com.sun.star.script.provider import XScriptProvider
from com.sun.star.script.provider import XScriptContext

def invokeSUM(*args):
    # get the doc from the scripting context which is made available to all scripts
    oDoc = XSCRIPTCONTEXT.getDocument()
    # retrieve the active sheet
    oSheet = oDoc.getSheets().getByName("sheet1")
    uurl = 'com.sun.star.sheet.FunctionAccess'
    FP = uno.getComponentContext().ServiceManager.createInstance(uurl)
    oRange = oSheet.getCellRangeByName("A1:A4")
    aData = oRange.getDataArray()
    aA = ()
    for n in aData:
        aA = aA + (n[0],)
    jj = FP.callFunction("SUM", aA)
    oSheet.getCellRangeByName("B1").ssetString("SUM(A1:A4)=")
    oSheet.getCellRangeByName("B2").setString(jj)
    return None

def invokeCOUNTIF(*args):
    # get the doc from the scripting context which is made available to all scripts
    oDoc = XSCRIPTCONTEXT.getDocument()
    # retrieve the active sheet
    oSheet = oDoc.getSheets().getByName("sheet1")
    uurl = 'com.sun.star.sheet.FunctionAccess'
    FP = uno.getComponentContext().ServiceManager.createInstance(uurl)
    oRange = oSheet.getCellRangeByName("A1:A4")
    aData = oRange.getDataArray()
    aA = ()
    for n in aData:
        aA = aA + (n[0],)
    bB = ("<3",)
    cC = (aA,bB)
    kk = FP.callFunction("COUNTIF",cC)
    oSheet.getCellRangeByName("C1").setString("COUNTIF(A1:A4,<3)=")
    oSheet.getCellRangeByName("C2").setString(kk)
    return None
Comment 1 Joel Madero 2013-02-01 16:06:13 UTC
This question should go to user list or ask libre office as it's not a report of a bug, it's a request for assistance with code. 

Closing this bug as INVALID, I'm sure someone on the user list will be able to help.

Thanks for your understanding

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.