Bug 112918 - Allow python functions to be called from cell formulas
Summary: Allow python functions to be called from cell formulas
Status: RESOLVED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: low enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2017-10-05 22:56 UTC by Quazgar
Modified: 2020-08-25 14:06 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Quazgar 2017-10-05 22:56:34 UTC
Description:
Currently, scripts can be written in Python, but using python functions in LO Calc formulas requires quite some overhead, as described here:

https://stackoverflow.com/questions/7591656/how-can-i-call-a-python-macro-in-a-cell-formula-in-openoffice-org-calc

It would be a lot easier for users to implement their own functions, if such functionality would be provided by LibreOffice itself.

Actual Results:  
 

Expected Results:
 


Reproducible: Always

User Profile Reset: 

Additional Info:
Idea:

I imagine it should be possible to simply require developers to add a Python decorator to the functions they want to expose to Calc cell functions, like so:

import uno
@uno.CalcFunction
def my_calculation(a, b):
    return sin(a) + cos(b)




User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Comment 1 Buovjaga 2017-11-03 14:36:40 UTC
I discussed with developers and the consensus was:
"if the reporter implements a function decarator or whatever that can generate the necessary boiler-plate to register an UNO add-in then we'll merge it"

Regarding patches:
https://wiki.documentfoundation.org/Development/gerrit/SubmitPatch

Regarding general development:
https://wiki.documentfoundation.org/Development
Comment 2 Alain Romedenne 2020-08-25 14:04:00 UTC
I would love to use the Python decorator described above … However

Python functions can be called from cells with the help of a Basic wrapper function as described in:
https://help.libreoffice.org/latest/en-US/text/sbasic/guide/basic_2_python.html

This is feasible regardless of the Python routine location:
o  user module
o  LibO shared module
o  document-based module
o  user or shared extension module

Macro x-language calls are detailed here:
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification

I suggest to close this incident as WONTFIX since a workaround exists.
Comment 3 Buovjaga 2020-08-25 14:06:42 UTC
Ok, let's close