hi Bernard,

thank you for your reply.  I created a javascript library named "JSLib1"
and in it a macro named "StringContains", and I placed in it your
example JS code.



then in OpenOffice Basic Macros I have the module "Module1".  you can
see the code at
https://gist.github.com/TwentyOneSolutions/38f38c1ebf99a85b6da5

when I enter into a cell =getScriptVersion() I see the expected value of
1.04

when I enter into a cell =contains("abc", "b") I get Err:508 which
according to https://wiki.openoffice.org/wiki/Calc_Error_Codes means
that a parenthesis is not closed properly.

trying to call the macro TestJsCall shows the following error:



Macro Library JSLib1 not found, which seems to be different from Err:508.

what am I missing?

thanks again,

Igal Sapir
Lucee Core Developer
Lucee.org <http://lucee.org/>

On 3/13/2015 6:09 AM, Bernard Marcelly wrote:
> 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
>

Reply via email to