Hi,
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;
Explanations:
- 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 =
oDocScriptProvider.getScript("vnd.sun.star.script:Library1.ExistsTerm.js?language=JavaScript&location=document")
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
<https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework>
The arguments of the invoke method is described in
<https://www.openoffice.org/api/docs/common/ref/com/sun/star/script/XInvocation.html#invoke>
Igal @ Lucee.org 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?
TIA
p.s. this is a crosspost with
http://stackoverflow.com/questions/29025195/openoffice-calc-javascript-function
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org