OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Handling Template Information - Basic

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

PostPosted: Wed Apr 28, 2004 2:14 pm    Post subject: Handling Template Information - Basic Reply with quote

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
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Wed Apr 28, 2004 4:43 pm    Post subject: Reply with quote

Nice dfrench.
Templates are sometimes pretty confusing, so thank you!
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group