Convert DateTime fields to ordinary text portions

Creating Extension - 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 forum is not for asking questions about writing your own macros.

Convert DateTime fields to ordinary text portions

Postby Lupp » Wed Oct 10, 2018 12:51 pm

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 6 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 6.1 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Let's create a powerful UFO: United Free Office!
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2042
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Convert DateTime fields to ordinary text portions

Postby JeJe » Wed Oct 10, 2018 1:33 pm

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.
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 249
Joined: Wed Mar 09, 2016 2:40 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest