Identify TextField through iteration
Identify TextField through iteration
Hello all.
I'm newbie at this forum but I'm searching in since days ago looking for an information about TextFields:
I have a document with many Date fields inserted on it, with different shifts in days. I'd like to change only one of it using a macro, I know how to change the Date modifying "Adjust" field, I know how to iterate through all TextField in the document, but I could'nt find any method to identify the DateTime I want to change, is there any way to identify inserted TextFields?
Regards and thanks in advanced
I'm newbie at this forum but I'm searching in since days ago looking for an information about TextFields:
I have a document with many Date fields inserted on it, with different shifts in days. I'd like to change only one of it using a macro, I know how to change the Date modifying "Adjust" field, I know how to iterate through all TextField in the document, but I could'nt find any method to identify the DateTime I want to change, is there any way to identify inserted TextFields?
Regards and thanks in advanced
LibreOffice 6 on Debian Testing
Re: Identify TextField through iteration
Install the MRI extension. Latest version on github: https://github.com/hanya/MRI/blob/maste ... -1.3.1.oxt
Restart the office.
Open a text document with fields.
menu:Tools>AddOns>Mri
Double-click the line starting with "TextFields" on the properties tab.
Switch to the methods tab and double-click "createEnumeration" then "nextElement".
Go back and double-click "nextElement" until you have the wanted date field. It has a property "DateTimeValue" which is a com.sun.star.util.DateTime struct.
Hit Ctrl+H for a code snippet.
In your own code create a new DateTime struct, fill in values and assign it to the DateTimeValue property of your object.
[Tutorial] Introduction into object inspection with MRI
Restart the office.
Open a text document with fields.
menu:Tools>AddOns>Mri
Double-click the line starting with "TextFields" on the properties tab.
Switch to the methods tab and double-click "createEnumeration" then "nextElement".
Go back and double-click "nextElement" until you have the wanted date field. It has a property "DateTimeValue" which is a com.sun.star.util.DateTime struct.
Hit Ctrl+H for a code snippet.
In your own code create a new DateTime struct, fill in values and assign it to the DateTimeValue property of your object.
[Tutorial] Introduction into object inspection with MRI
Please, 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
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: Identify TextField through iteration
Hi,
I can't see a way to identify a given date field among other date fields, but inserting a bookmark at that field will help. Let's say this bookmark is named "theDate":
Regards.
I can't see a way to identify a given date field among other date fields, but inserting a bookmark at that field will help. Let's say this bookmark is named "theDate":
Code: Select all
doc = thiscomponent
datebookmark = doc.Bookmarks.getByName("theDate")
datefield = datebookmark.Anchor.TextField
datefield.Adjust = 60*24
Last edited by hubert lambert on Thu Mar 07, 2019 3:47 pm, edited 1 time in total.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
-
- Volunteer
- Posts: 1549
- Joined: Wed Jun 24, 2015 12:56 am
- Location: Colorado, USA
Re: Identify TextField through iteration
Using the MRI tool on a Writer document with some inserted datetime values I can test a textfield with
if it returns TRUE I know that textfield contains a datetime value.
Code: Select all
oTextField.getPropertySetInfo().hasPropertyByName("DateTimeValue")
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Re: Identify TextField through iteration
Basic code produced by Mri with LO 6.0
Code: Select all
Sub Snippet
Dim oTextFields As Variant
Dim oObj1 As Variant
Dim oObj2 As Variant
Dim bIsDate As Boolean
Dim nIsFieldDisplayed As Integer
Dim nIsFieldUsed As Single
Dim bIsFixed As Boolean
Dim bIsFixedLanguage As Boolean
Dim nNumberFormat As Long
Dim aDateTimeValue As New com.sun.star.util.DateTime
oTextFields = ThisComponent.getTextFields()
oObj1 = oTextFields.createEnumeration()
oObj2 = oObj1.nextElement()
bIsDate = oObj2.IsDate
nIsFieldDisplayed = oObj2.IsFieldDisplayed
nIsFieldUsed = oObj2.IsFieldUsed
bIsFixed = oObj2.IsFixed
bIsFixedLanguage = oObj2.IsFixedLanguage
nNumberFormat = oObj2.NumberFormat
aDateTimeValue = oObj2.DateTimeValue
End Sub
Please, 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: Identify TextField through iteration
Diez wrote:...but I could'nt find any method to identify the DateTime I want to change,...
By what do you want to identify the TextField you are talking of?
-- By its value (date only or date-time)? What if there is more than one occurrence?
-- By position in the document? How to describe that position? If you cannot address the field, you cannot identify it.
-- By what else?
(If there are dates defined with an offset by days, I don't know anyway how to handle them.)
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Identify TextField through iteration
Hello all.
I've tested the Bookmarks proposal and I think is enough for me. I've discarded the MRI because implies (I think) to install on all computers where it will used the code. The code will be into a template to be distributed. The idea is to install as little as possible.
In any case, is strange for me that inserted fields have not any kind of identification.
Thank you
I've tested the Bookmarks proposal and I think is enough for me. I've discarded the MRI because implies (I think) to install on all computers where it will used the code. The code will be into a template to be distributed. The idea is to install as little as possible.
In any case, is strange for me that inserted fields have not any kind of identification.
Thank you
LibreOffice 6 on Debian Testing
Re: Identify TextField through iteration
MRI is a tool for examining objects and seeing what properties they have - you only need to install it on the computer you write the code on as a help with writing the code. I consider it indespensible - you want it!
Basic IDE Tools is another every helpful extension:
https://extensions.openoffice.org/fr/pr ... -ide-tools
Basic IDE Tools is another every helpful extension:
https://extensions.openoffice.org/fr/pr ... -ide-tools
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Identify TextField through iteration
I would like to add a few remarks.
To get the DateTime fields we needn't loop through all the TextFields. The first TextField of DateTime type (supporting the service "com.sun.star.text.TextField.DateTime") we find points to the common TextFieldMaster of all DateTime fields contained in the document. That object in turn gives access to all its dependent fields via an array object.
The suggestion to use (a) bookmark(s) to point to DateTime fields needing an update now and then is well suitable, but the bookmarks will be shown in the navigator panel, and may cause some irritation probably. There is an alternative to "name" any TextField.
It has an .Anchor property, and the Anchor is prepared to accept a HyperLink. There are the three String properties HyperLinkURL, HyperLinkTarget, and HyperLinkName. The HyperLinkName can be (slightly mis-)used as a name for the TextField itself without setting an URL or a Target.
See attached example.
===Edit1 2019-03-08 16:15 CET===
Forget it!
What I stated otherwise seems to be valid.
To get the DateTime fields we needn't loop through all the TextFields. The first TextField of DateTime type (supporting the service "com.sun.star.text.TextField.DateTime") we find points to the common TextFieldMaster of all DateTime fields contained in the document. That object in turn gives access to all its dependent fields via an array object.
The suggestion to use (a) bookmark(s) to point to DateTime fields needing an update now and then is well suitable, but the bookmarks will be shown in the navigator panel, and may cause some irritation probably. There is an alternative to "name" any TextField.
It has an .Anchor property, and the Anchor is prepared to accept a HyperLink. There are the three String properties HyperLinkURL, HyperLinkTarget, and HyperLinkName. The HyperLinkName can be (slightly mis-)used as a name for the TextField itself without setting an URL or a Target.
See attached example.
===Edit1 2019-03-08 16:15 CET===
Forget it!
This seems to work first - and it works as long as the file is open. However, the HyperLinkName isn't saved if not also a link is set.Lupp wrote:The HyperLinkName can be (slightly mis-)used as a name for the TextField itself without setting an URL or a Target.
What I stated otherwise seems to be valid.
- Attachments
-
- aooMarkDateTimeFields_1.odt
- (23.62 KiB) Downloaded 239 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München