Implement a new function to use in Writer's textfields

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
tiberio.melo
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

Implement a new function to use in Writer's textfields

Post 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?
OpenOffice 3.1 on Ubuntu 16.04
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Post 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
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
tiberio.melo
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

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

Post 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.
OpenOffice 3.1 on Ubuntu 16.04
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
tiberio.melo
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

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

Post 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").
OpenOffice 3.1 on Ubuntu 16.04
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

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

Post 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 
Attachments
Convert Value to Words..odt
(18.39 KiB) Downloaded 127 times
Last edited by Arineckaig on Sun Apr 16, 2017 8:23 pm, edited 1 time in total.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
tiberio.melo
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

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

Post 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.
OpenOffice 3.1 on Ubuntu 16.04
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post by RoryOF »

Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

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

Post 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.
Attachments
Convert Value to Words. - REV.odt
(18.17 KiB) Downloaded 129 times
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Post Reply