Manual proceeding may be a bit ... unhandy.
Therefore the following pieces of code:
Code: Select all
REM Raw! Not very thoroughly analyzed and only superficially tested!
Sub detachTemplate()
memorize = True
uPropName = "memorizedTemplate"
props = ThisComponent.DocumentProperties
If memorize Then
tn = props.TemplateName
tu = props.TemplateURL
uProps = props.UserDefinedProperties
h = getPropertyValueIfExisting(uProps, uPropName)
If IsNull(h) Then
uProps.addProperty(uPropName,,tu)
EndIf
EndIf
props.TemplateName = ""
props.TemplateURL =""
End Sub
Sub reAttachMemorizedTemplate()
uPropName = "memorizedTemplate"
props = ThisComponent.DocumentProperties
uProps = props.UserDefinedProperties
h = getPropertyValueIfExisting(uProps, uPropName)
If NOT IsNull(h) Then
tURL = h
tURLSpl = Split(tURL, "/")
tName = tUrlSpl(Ubound(tURLSpl))
props.TemplateURL = tURL
props.TemplateName = tName
REM To avoid conflicts iof later a different template may be attached:
uProps.removeProperty(uPropName)
EndIf
End Sub
Function getPropertyValueIfExisting(pPropertyContainer As Object, pName As String)
getPropertyValueIfExisting = Nothing
On Local Error Goto fail
getPropertyValueIfExisting = pPropertyContainer.getPropertyValue(pName)
fail:
End Function
With one example everything worked in LibreOffice V 7.2 and also in AOO V 4.1.
The extension "Template Changer" was discussed more than once in this forum. It seems to be still maintained for LibO. (I never used it ...)