In this very exceptional case it might be forgivable to resort to custom code.
Due to an accidental coincidence I recently wrote a bit of code for a related task answering a question in a different forum.
The code was written and "debugged" under LibreOffice V6.1.1.2. It also worked under AOO, but the appearance of the fields needed to be updated expressly in addition: Press Ctrl+F9
twice to do so.
The code is for the
conversion of ALL DateTimeFields in a Writer document to a unified format. You can apply it on old documents, and also on new ones, of course, before saving them, e.g.
The code:
Code: Select all
Sub unifyDateTimeFieldFormats(Optional pDoc As Object, _
Optional pLang As String, _
Optional pDateFormatString As String, _
Optional pTimeFormatString As String)
REM Be careful! Undo does NOT work for the changes made by this routine!
theDoc = IIf(IsMissing(pDoc), ThisComponent, pDoc)
If NOT theDoc.SupportsService("com.sun.star.text.TextDocument") Then Exit Sub
fStringLang = IIf(IsMissing(pLang), "en", pLang)
REM Use a language for which your format codes are valid.
Dim fmtLocale As New com.sun.star.lang.Locale
fmtLocale.Language = fStringLang
dateFstring = IIf(IsMissing(pDateFormatString), "YYYY-MM-DD", pDateFormatString)
timeFstring = IIf(IsMissing(pTimeFormatString), "HH:MM:SS", pTimeFormatString)
dateFkey = findCreateNumberFormat(dateFstring, theDoc, fmtLocale)
timeFkey = findCreateNumberFormat(timeFstring, theDoc, fmtLocale)
For Each tf In theDoc.TextFields
If NOT tf.SupportsService("com.sun.star.text.TextField.DateTime") Then Goto nexttf
Select Case tf.IsDate
Case True : tf.NumberFormat = dateFkey
Case False : tf.NumberFormat = timeFkey
End Select
nexttf:
Next tf
End Sub
The Sub uses the function
findCreateNumberFormat next to completely taken from Andrew Pitonyaks's texts. (Only the errors - if any - are mine.) This function is also contained in the attached demo document.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München