Hi,
I would add in a cell of a Calc spreadsheet the last save date&time. I know this is possible in Writer, but I cannot find the equivalent in Calc. Does this function exist?
I’m using LibreOffice v7.5.0
Hi,
I would add in a cell of a Calc spreadsheet the last save date&time. I know this is possible in Writer, but I cannot find the equivalent in Calc. Does this function exist?
I’m using LibreOffice v7.5.0
In Writer you can insert the ModificationDate
(in fact also the time) of a component using a TextField
. This kind of TextField isn’t supported by Calc, and there is no standard function returning the respective DocumentProperty.
I personally prefer to show this information (and more) in the frame title automatically.
For you I extracted the respective part of my code, and reworked it slightly to get a function usable in Calc:
Function componentPropertyLastModified(Optional pFormatString As String, Optional pComponent)
If IsMissing(pFormatString) Then pFormatString = ""
If IsMissing(pComponent) Then pComponent = ThisComponent
componentPropertyLastModified = "N/A"
On Local Error Goto fail
Dim lm, omittable, out REM out appended 2023-10-12 10:12:56 UTC
lm = pComponent.DocumentProperties.ModificationDate
With lm
If .Month=0 Then lm = pComponent.DocumentProperties.CreationDate
If .Month=0 Then
Exit Function
End If
Dim d As Double, t As Double, dt As Double
d = DateValue("" & .Year & "-" & .Month & "-" & .Day)
omittable = 0.0 '.NanoSeconds * 1E-9
t = (((omittable + .Seconds)/60 + .Minutes)/60 + .Hours)/24
dt = d + t
End With
If pFormatString<>"" Then
out = Format(dt, pFormatString)
Else
out = dt
EndIf
componentPropertyLastModified = out
fail:
End Function
=== Editing much later (about 2023-10-12 10:12:56 UTC) ===
Just saw that the given code won’t work if Option Explicit
is enabled. The reason is the variable out
introduced when an older version of the function was adapted for this post.
In fact I should have changed the name of the function, too.
=== End Edit ===
I was searching for an easy way as in Writer… I’m not into the LibreOffice implementation details, so I was thinking the TextField was near to be available even in Calc… I will try to use your code, thanks for the help.
Can be a little shorter:
d=CDateFromUnoDateTime(pComponent.DocumentProperties.ModificationDate)
' ---
This is a very important feature and must be a basic feature of Calc without any user functions! I hope that somebody could be able to add this in future versions!
…but be prepared for the fact that developers will take your statement “a very important feature” with a fair amount of skepticism
This was filed on the LibreOffice bug tracker already in 2012 (!):