Page 1 of 1

Implement a new function to use in Writer's textfields

Posted: Sat Apr 15, 2017 1:33 pm
by tiberio.melo
I have recently implemented a function that returns the value in full of a number. For example, for $ 3.45 the function returns me the string: "three dollars and forty-five cents".
I was able to make this function available in Calc ("com.sun.star.sheet.AddIn"), where it works perfectly.
Now I would like to know how to increment the set of functions available in Writer to include this new function so that I can use it along with textfields.
Does anyone know how to do this? By the way, where did the functions available in Writer for textfields were implemented?

Re: Implement a new function to use in writer's textfields

Posted: Sat Apr 15, 2017 1:51 pm
by Zizi64
There is an Extension named NUMBERTEXT (MONEYTEXT). It can convert the numbers to text for many languages.

https://ask.libreoffice.org/en/question ... functions/
https://extensions.libreoffice.org/exte ... mbertext-1
https://forum.openoffice.org/fr/forum/v ... 18&t=22839

Re: Implement a new function to use in writer's textfields

Posted: Sat Apr 15, 2017 2:08 pm
by tiberio.melo
Hi Zizi64,

Initially thank you very much for your response.
However the articles below and the extension mentioned implement the function only in Calc (something I have done successfully).
My problem is to be able to make the function available in Writer and able to use it together with textfields.
For example, generate the value in full in a textfield based on the value of a variable defined in another textfield.
I am about a week looking for information on how to do this and all I got was info on how to create functions in Calc; But nothing about how to do this in Writer.

Re: Implement a new function to use in writer's textfields

Posted: Sat Apr 15, 2017 2:23 pm
by RoryOF
You can certainly save this code and access it as a macro from Writer, even from a menu bar entry or a toolbar button; often (always?) the values returned from OO's built in fields can not be directly accessed for manipulation - I can vaguely remember discussion on numbering of columns which involved manipulation of the Page Number field; I think (not certain) that this was eventually solved some other way.

It might be that the simplest solution to your problem is to extend your code to call or emulate the underlying API calls that ask for the input you require, then manipulate it by your existing code and output it as desired.

Re: Implement a new function to use in writer's textfields

Posted: Sat Apr 15, 2017 2:42 pm
by tiberio.melo
Let me give an example to make the problem clearer.
I have a document (form) where you used textfields to standardize the fill.
One of the information that is requested in the form is the financial amounts involved.
The user types, for example, $ 325.00 in a texfield, and I would need that, using my function implemented in Writer, another textfield would display the value in full.
Currently Writer has some functions that manipulate information coming from textfield (for example, maximum, minimum, average, sum, etc.), and I just want to create an additional function in this group (something similar that is done in Calc via one- Package implemented in "com.sun.star.sheet.AddIn").

Re: Implement a new function to use in Writer's textfields

Posted: Sat Apr 15, 2017 7:46 pm
by Arineckaig
The user types, for example, $ 325.00 in a texfield, and I would need that, using my function implemented in Writer, another textfield would display the value in full.
Almost certainly a macro may be needed to initiate the function from a Writer Form Document. For example if the function is to be triggered by a button on the document, suitable coding to call your function might be:

Code: Select all

	oForm = oEv.Source.Model.Parent
	Num$ =  oForm.getByName("Value Box").Text 
	oForm.getByName("txtOutput").Text = USCurrencyToWords(Num$)
To avoid potential currency format problems, it is preferable that the source should be a formatted field.

A demo document is attached, so that you may readily replace its sample "USCurrencyToWords" function with your own.
 Edit: Later in this thread is a revised and potentially more general version in that it eliminates reliance on one of the named form controls 

Re: Implement a new function to use in Writer's textfields

Posted: Sun Apr 16, 2017 3:01 am
by tiberio.melo
Hi Arineckaig,
Thanks for your reply, but unfortunately the proposed solution does not solve my problem.
The point is that using macro involves updating the code whenever new fields appear; Which makes maintenance difficult.
In addition the user would always have to trigger the macro in order for the document to be updated, which is something that makes data reliability questionable.
For all this, I would like to create a function that is accessible in Writer's textfields.

Re: Implement a new function to use in Writer's textfields

Posted: Sun Apr 16, 2017 8:42 am
by RoryOF

Re: Implement a new function to use in Writer's textfields

Posted: Sun Apr 16, 2017 11:23 am
by RoryOF
This thesis may be of assistance
https://www.ifis.uni-luebeck.de/~moelle ... tuan09.pdf

I doubt that there will be any easy way to do what you require, apart from writing a suitable function in a programming language and recompiling OO source code to incorporate that function.

Re: Implement a new function to use in Writer's textfields

Posted: Sun Apr 16, 2017 1:28 pm
by Arineckaig
Without knowing your precise requirement I suspect, as indicated by RoryOF, you may well need to recompile the source code to make functions in Writer behave as those in Calc. On the other hand there may yet be some merit in working with what is already available to Writer. The code in attached demo file has been slightly revised to give some pointers:
In addition the user would always have to trigger the macro in order for the document to be updated, which is something that makes data reliability questionable.
The macro to apply the function can be triggered by, and only by, pressing a specified key: for example, the RETURN key after entering numeric data.
The point is that using macro involves updating the code whenever new fields appear; Which makes maintenance difficult.
Again without knowing the circumstances under which 'new fields appear' the field(s) used for entering numeric data can readily be copied with each making use of the same macro code: the two sample duplicate entry fields can be further added to.

If distinct fields are required for the output of each entry field, various options with varying degrees of complexity could well be available. Any solution, however, will largely depend on the specific requirement which may have limited relevance generally to the forum.

Re: Implement a new function to use in Writer's textfields

Posted: Sun Apr 16, 2017 7:07 pm
by RoryOF
Tidying my papers I came across a reference to this:
simple openoffice basic code to possibly create and set a variable field

Perhaps this will be helpful in the context of the thread problem.