openoffice-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernard Marcelly <>
Subject Re: OpenOffice Calc Javascript Function
Date Fri, 13 Mar 2015 13:09:38 GMT

If you intend to use a JavaScript function in a cell formula, forget about it.
First, you cannot directly call a JavaScript function from a cell formula. The 
formula should call a Basic function that calls the JavaScript function.
Second, the formula will provide an error at document loading, because at this 
instant the script library is not yet accessible.

If you want to use a JavaScript function from a Basic macro, you have to use the 
script provider.

Suppose you want to create function ExistsTerm(arg1, arg2) in JavaScript.

- Create in your document a JavaScript library named Library1
- Then create a JavaScript module named : ExistsTerm
- Edit this module : replace all the lines by this line:
ARGUMENTS[0].indexOf(ARGUMENTS[1]) > -1;
- The name of the function is the name of the module.
- ARGUMENTS is an array of all the arguments.
- The result of the function is by default the last evaluation.

Here is a Basic macro that uses the JavaScript function. Attention, the email 
has split long lines.

Sub Main3
Dim oDocScriptProvider As Object, oScript As Object
Dim result As Variant

oDocScriptProvider = ThisComponent.getScriptProvider()
oScript = 
result = oScript.invoke(Array("Apache OpenOffice is the best", "OpenOffice"), 
Array(), Array())
MsgBox("Term exists : " & result)
End Sub

The Scripting Framework is described in the Developer's Guide
The arguments of the invoke method is described in

Igal @ a écrit le 2015-03-13 06:50 :
> Hi all,
> I want to write a simple function to be used in OpenOffice Calc.
> It would return true if the cell's value contains a substring, e.g.
> |function contains(string, substring) {
>      return (string.indexOf(substring) > -1);
> }|
> But I can't find any documentation or examples on that.
> Any ideas?
> p.s. this is a crosspost with

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message