[Solved] Using javascript functions in calc
[Solved] Using javascript functions in calc
I'd like to write a function in javascript and use it from a calc sheet. It turns out that I seem to be the first one to try that, or everybody else who tried that was clever enough to not need a documentation.
Last edited by MrProgrammer on Sat Feb 22, 2020 5:59 am, edited 1 time in total.
Reason: Tagged ✓ [Solved]
Reason: Tagged ✓ [Solved]
OpenOffice 2.4 on Linux
Re: Using javascript functions in calc
I want to do the same thing, and came here in the hope of finding out how to do it.
open office 3.2.0 on Mint9
- MrProgrammer
- Moderator
- Posts: 5279
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Using javascript functions in calc
Perhaps Tools, Macros, Organize Macros, Javascript, My Macros, Create.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
-
- Volunteer
- Posts: 1160
- Joined: Mon Oct 08, 2007 1:26 am
- Location: France, Paris area
Re: Using javascript functions in calc
Hi,
Calc is only designed to use functions created in OOoBasic. See Issue 24829.
If you want it to use a function created in a script language (JavaScript, BeanShell, Python) you need to create a wrapper function in Basic. Your Calc formula will call the wrapper function, which in turn will call the script function, get its result and return it as a result.
The Basic wrapper function must call the script using the Scripting Framework, which is not really simple (you can find examples in the forums).
But there is another problem : if you put the script function and wrapper function in a Calc document, the formula will throw an error at loading of the document, because at this time the script is not yet loaded. A work-around is to store the script function in My Macros, and load the document only when OpenOffice.org is already loaded.
With Python you can create an add-in. This is not a simple script but a complete Uno component, to be installed in OpenOffice.org with an extension. It will be integrated as a new Calc function. But this is too complex for an ordinary user.
Calc is only designed to use functions created in OOoBasic. See Issue 24829.
If you want it to use a function created in a script language (JavaScript, BeanShell, Python) you need to create a wrapper function in Basic. Your Calc formula will call the wrapper function, which in turn will call the script function, get its result and return it as a result.
The Basic wrapper function must call the script using the Scripting Framework, which is not really simple (you can find examples in the forums).
But there is another problem : if you put the script function and wrapper function in a Calc document, the formula will throw an error at loading of the document, because at this time the script is not yet loaded. A work-around is to store the script function in My Macros, and load the document only when OpenOffice.org is already loaded.
With Python you can create an add-in. This is not a simple script but a complete Uno component, to be installed in OpenOffice.org with an extension. It will be integrated as a new Calc function. But this is too complex for an ordinary user.
Bernard
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1