Bug 60158 - python cannot invoke LO cacle built-in functions
Summary: python cannot invoke LO cacle built-in functions
Status: RESOLVED INVALID
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.0.0.2 rc
Hardware: x86 (IA32) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-01 13:20 UTC by jmxhyz
Modified: 2013-11-17 19:14 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
This document is embedded python script. (16.11 KB, application/vnd.oasis.opendocument.spreadsheet)
2013-02-01 13:20 UTC, jmxhyz
Details

Note You need to log in before you can comment on or make changes to this bug.
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