[Solved] Copy text fields content as strings
[Solved] Copy text fields content as strings
hi there,
I have this test .odt file which has 3 text fields with text and numbers inside (it's a medical report template which patient name, date of birth and exam date)
I need a macro to extract the text in those fields as 3 separate strings.
basically in the mockup file I need to extract the string: DONALD DUCK from first field, 10-11-1955 from the second and 27-06-14 from the third one.
is there any basic code function that allows me to "read" a text field and copy it as a string?
I have this test .odt file which has 3 text fields with text and numbers inside (it's a medical report template which patient name, date of birth and exam date)
I need a macro to extract the text in those fields as 3 separate strings.
basically in the mockup file I need to extract the string: DONALD DUCK from first field, 10-11-1955 from the second and 27-06-14 from the third one.
is there any basic code function that allows me to "read" a text field and copy it as a string?
- Attachments
-
- test_file.odt
- (18.38 KiB) Downloaded 261 times
Last edited by Tommy on Sat Jun 28, 2014 4:51 pm, edited 1 time in total.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Re: [REQ] copy text fields content as strings
What is to happen to the extracted text? Is it to be placed in separate files, or reused within the test file? How?
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
Re: [REQ] copy text fields content as strings
the extracted string will reused in another macro which compares the correspondence between file name and text fields data, anyway I won't go in further details since I already know how to do this second part and I do not need help about it.
the only thing I miss is how to extract those simple strings from those text fields in that file
once I have those strings I can do all the other stuff.
the macro code I need should identify the 3 text fields inside the .odt file and then read and copy the text of each one.
the only thing I miss is how to extract those simple strings from those text fields in that file
once I have those strings I can do all the other stuff.
the macro code I need should identify the 3 text fields inside the .odt file and then read and copy the text of each one.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Re: [REQ] copy text fields content as strings
I found this at
https://wiki.openoffice.org/wiki/Docume ... ith_fields
viewtopic.php?f=7&t=65817#p292326
but I haven't read it to verify that.
https://wiki.openoffice.org/wiki/Docume ... ith_fields
This macro may be echoed atConverting fields into text
Writer does not provide any easy way to convert field contents into text. To do this, you need to copy the field contents and paste them back as unformatted text. This is not a very good solution if you have hundreds of fields that you want to change, but you could use a macro to automate the process.
A suggested macro is provided here: http://www.oooforum.org/forum/viewtopic.phtml?t=115398
viewtopic.php?f=7&t=65817#p292326
but I haven't read it to verify that.
| Edit: The above copy of the macro on forum.openoffice.org has been tweaked. For completeness, I list here the original code from oooforum, posting 115398
Code: Select all |
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
Re: [REQ] copy text fields content as strings
thanks for your help but it's not exactly what I'm looking for.
I do not need to "convert" the text field into plain text, like that macro does
in the test file I have 3 text field (those written in bold light blue) and if you double click on them you will see that each one has a name and a value
what I need is a macro that "reads" that value and copies it as as string.
in the test file the 1st field is "fldNome" and it's value is "DONALD DUCK",
the 2nd is "fdlNascita" and has a "10-11-1955" value,
the 3rd is "fldEsame" and has a "27-06-2014" value.
all values are in simple text format.
the macro I'm looking for should read those values and extract them as 3 separated text strings.
the output should be: "DONALD DUCK", "10-11-1955" and "27-06-2014"
I will later assemble those strings into a single string which will be "DONALD DUCK_101155_270614" since I already know how to manipulate text strings
I do not need to "convert" the text field into plain text, like that macro does
in the test file I have 3 text field (those written in bold light blue) and if you double click on them you will see that each one has a name and a value
what I need is a macro that "reads" that value and copies it as as string.
in the test file the 1st field is "fldNome" and it's value is "DONALD DUCK",
the 2nd is "fdlNascita" and has a "10-11-1955" value,
the 3rd is "fldEsame" and has a "27-06-2014" value.
all values are in simple text format.
the macro I'm looking for should read those values and extract them as 3 separated text strings.
the output should be: "DONALD DUCK", "10-11-1955" and "27-06-2014"
I will later assemble those strings into a single string which will be "DONALD DUCK_101155_270614" since I already know how to manipulate text strings
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Re: [REQ] copy text fields content as strings
Hello
I have no solution but maybe this can help you
viewtopic.php?f=20&t=2786&hilit=userfields
Pitonyak did placed there a macro. With the knowledge of that macro and MRI i can see the fields. I have not test it with a macro.
Romke
I have no solution but maybe this can help you
viewtopic.php?f=20&t=2786&hilit=userfields
Pitonyak did placed there a macro. With the knowledge of that macro and MRI i can see the fields. I have not test it with a macro.
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
Re: [REQ] copy text fields content as strings
A reminder of the character named "Tommy": Stop OpenOffice Renaissance project (petition) Today he marks his personal wishes as a requirement:
Code: Select all
[REQ] copy text fields content as stringsPlease, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [REQ] copy text fields content as strings
REQ = request
get a life, Villeroy.
get a life, Villeroy.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Re: [REQ] copy text fields content as strings
Does the [Thisfield.Anchor.String] not assign the textfield content to your variable? You wouldn't assign it to itself, you'd assign it to the variable you wanted to have the text. That's how I interpreted the macro Rory posted.
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
Re: [REQ] copy text fields content as strings
Hallo
bye .....
so modify it to your needs, or hire profesional Programmers to spoonfeed yourself....thanks for your help but it's not exactly what I'm looking for....
bye .....
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Re: [REQ] copy text fields content as strings
hi MTP,MTP wrote:Does the [Thisfield.Anchor.String] not assign the textfield content to your variable? You wouldn't assign it to itself, you'd assign it to the variable you wanted to have the text. That's how I interpreted the macro Rory posted.
the macro Rory posted converts the text field into plain text so it does a completely different thing. try it on my test file to see what happens.
I need a macro to just "read" the text value which is inside the text field and to save it as a string to be processed in other macros I already know how to use
see my screenshot. I should figure how which code should I use to extract the DONALD DUCK value from the fldNome field.
@karolus
your comment is offensive and useless like the one from Villeroy.
get a life, too.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Re: [REQ] copy text fields content as strings
Well, I tried it (see attached). I had it print the stored variable to check, and it works like I guessed it did.Tommy wrote:...try it on my test file to see what happens.
- Attachments
-
- test_file.odt
- (13.28 KiB) Downloaded 209 times
Last edited by MTP on Sat Jun 28, 2014 5:50 pm, edited 1 time in total.
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
Re: [REQ] copy text fields content as strings
@MTP
thank you very much. your edited version of Rory's macro does exactly what I was looking for.
here's the correct working code
many thanks to you, to RoryOF and RPG who spent time trying to help and give good tips.

thank you very much. your edited version of Rory's macro does exactly what I was looking for.
here's the correct working code
Code: Select all
Sub ReadTextFields
Dim oFields : oFields = ThisComponent.getTextFields
Dim oEnum
Dim ThisField
Dim s As String
oEnum = oFields.createEnumeration
While oEnum.HasMoreElements
ThisField = oEnum.nextElement
s = ThisField.Anchor.String
Print s
Wend
End Sub
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Re: [REQ] copy text fields content as strings
Hallo
replacing with
Lazy bum !!
All you had to do wasRoryOF wrote:
Edit: The above copy of the macro on forum.openoffice.org has been tweaked. For completeness, I list here the original code from oooforum, posting 115398 Code: Select all
Sub FieldsToText 'Writer Dim oDoc,oFields,oEnum,ThisField oDoc = ThisComponent oFields = oDoc.getTextFields oEnum = oFields.createEnumeration While oEnum.HasMoreElements ThisField = oEnum.nextElement ThisField.Anchor.String = ThisField.Anchor.String Wend End Sub
Code: Select all
ThisField.Anchor.String = ThisField.Anchor.StringCode: Select all
print ThisField.Anchor.StringLibreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Re: [Solved] copy text fields content as strings
I'm a newbie about coding macros and that code tweak that looked so simple to an expert like you, was not immediate to me.
I see you prefer spending your time insulting people rather than giving help... shame on you.
this forum needs more people like Rory, RPG and MTF.
I see you prefer spending your time insulting people rather than giving help... shame on you.
this forum needs more people like Rory, RPG and MTF.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354