Implement a new function to use in Writer's textfields

Creating a macro - Writing a Script - Using the API

Implement a new function to use in Writer's textfields

Postby tiberio.melo » Sat Apr 15, 2017 1:33 pm

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
tiberio.melo
 
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

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

Postby Zizi64 » Sat Apr 15, 2017 1:51 pm

Tibor Kovacs, Hungary; LibreOffice4.4.7 - Portable versions: LO3.3.0-LO5.3.3 and AOO4.1.3; on Win7x64Prof.
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 5270
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby tiberio.melo » Sat Apr 15, 2017 2:08 pm

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
tiberio.melo
 
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

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

Postby RoryOF » Sat Apr 15, 2017 2:23 pm

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.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 24387
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Postby tiberio.melo » Sat Apr 15, 2017 2:42 pm

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
tiberio.melo
 
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

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

Postby Arineckaig » Sat Apr 15, 2017 7:46 pm

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   Expand viewCollapse view
   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 23 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).
OOo 4.1.1 on MS Windows XP MySQL and HSQLDB
Arineckaig
Volunteer
 
Posts: 804
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

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

Postby tiberio.melo » Sun Apr 16, 2017 3:01 am

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
tiberio.melo
 
Posts: 4
Joined: Sat Apr 15, 2017 12:12 pm

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

Postby RoryOF » Sun Apr 16, 2017 8:42 am

Apache OpenOffice 4.1.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 24387
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Postby RoryOF » Sun Apr 16, 2017 11:23 am

This thesis may be of assistance
https://www.ifis.uni-luebeck.de/~moeller/publist-sts-pw-and-m/source/papers/2009/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.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 24387
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Postby Arineckaig » Sun Apr 16, 2017 1:28 pm

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 24 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).
OOo 4.1.1 on MS Windows XP MySQL and HSQLDB
Arineckaig
Volunteer
 
Posts: 804
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

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

Postby RoryOF » Sun Apr 16, 2017 7:07 pm

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.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 24387
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland


Return to Macros and UNO API

Who is online

Users browsing this forum: Fraz627, Google [Bot] and 8 guests