Convert DateTime fields to ordinary text portions

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Convert DateTime fields to ordinary text portions

Post by Lupp »

By a question in a different forum Iwas pointed to the fact that TextFields, in specific DateTime fields addressed there, are not found by a search if matching the 'Search for' string.

I took the oportunity to consider this, and tend to judge that behaviour to be a "heritage bug". A textcursor spanning the range of the field is knowing the string well. It should not be to difficult to include it when searching.

Anyway some person writing a diary or minuting a discussions may want to insert dates or times as fields using a shortcut. The person may then want to be able to search for some of the inserted fields. Difficult thing?

It gets rather simple if the person decides to definitely convert the DateTime (date or time) fields to ordinary text portions. How to do so for a complete text document in Writer, including any substructures (frames, tables, nested specimen of these kinds; shapes don't accept TextFields) by a few lines of code is demonstrated in the attached example.
ask168218DateTimFieldsReplaceWithStrings_2.odt
(31.83 KiB) Downloaded 299 times
If there is an additional need to harmonize the formats (two classes for dates and times e.g.) or to convert Time fields to DateTime fields in advance of conversion, please report your case. I'm not the most important user of this tool. As it is presented here, the number formats and the text formats as well are preserved.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Convert DateTime fields to ordinary text portions

Post by JeJe »

The Edit Fields dialog box isn't very good. Perhaps not difficult though to make an alternative one that lists all the date fields at once.

A custom character style could be used for dates.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply