dfrench Moderator

Joined: 03 Mar 2003 Posts: 1605 Location: Wellington, New Zealand
|
Posted: Wed Apr 28, 2004 2:14 pm Post subject: Handling Template Information - Basic |
|
|
There have been a few posts about the use of Templates in the writer forum.
It may be useful to replace the styles in a document by those from another document or template and then retain the link to that document as though it was the template used for original creation. setTemplateData below is an example of doing that. To make this into a practical tool, you could add a filepicker infront of it to set the filename and template name (replacing the constants shown here); also the time should be set if the template maintenance function is to be bulletproof.
getTemplateData shows the current settings of template data from the docinfo
These work for me; your milage may vary.
| Code: | Sub setTemplateData
odoc=thiscomponent
' the information about the template used to create/maintain this doc is in documentinfo
curl=converttourl("c:\program files\openoffice.org1.1.1\user\template\testtemplate4.stw")
styles=odoc.getStyleFamilies() 'get the interface to load styles
styles.loadStylesFromURL(curl,Array()) ' by default loads & overrides all styles
odocinfo=odoc.getDocumentInfo()
odocinfo.Template="testtemplate4"
odocinfo.TemplateFilename=curl
' set to today
odocinfo.TemplateDate.Year=Year(now())
odocinfo.TemplateDate.Month=Month(now())
odocinfo.TemplateDate.Day=Day(Now())
End Sub
Sub getTemplateData
odoc=thiscomponent
' the information about the template used to create/maintain this doc is in documentinfo
odocinfo=odoc.getDocumentInfo()
templatename=odocinfo.Template
templatefile=odocinfo.TemplateFilename
yr=odocinfo.TemplateDate.Year
mth=odocinfo.TemplateDate.Month
Dy=odocinfo.TemplateDate.Day
Datestr=format(dy,"00")&":"&format(mth,"00")&":"&format(yr,"0000")
msgbox "Template "&templatename & chr(13)&"File "& templatefile &chr(13)&"Date "&datestr
End Sub |
|
|