Hello,
I have my delphi application which communicates with OpenOffice (application serves like a document manager). I did my template with macros which servers an event like a new document, document is closed etc. I use to call LoadComponentFromUrl with AsTemplate parameter from my application to open a new document with my template. It works fine. But I need to set my template as default template for OpenOffice Writer. I know how to do manually (File > Template > Organize), but don't know how to do from my application. I looked for some solution, but i didn't find anything. Could anybody give me any advice? Thanks
[Solved] Set default template
[Solved] Set default template
Last edited by struhadlo on Tue Nov 06, 2012 6:50 pm, edited 2 times in total.
Linux Mint 11, OpenOffice 3.4.1
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Set default template
I tried this experiment, and it seemed to work, though I wouldn't be surprised if there is a more direct solution.struhadlo wrote:Hello,
I have my delphi application which communicates with OpenOffice (application serves like a document manager). I did my template with macros which servers an event like a new document, document is closed etc. I use to call LoadComponentFromUrl with AsTemplate parameter from my application to open a new document with my template. It works fine. But I need to set my template as default template for OpenOffice Writer. I know how to do manually (File > Template > Organize), but don't know how to do from my application. I looked for some solution, but i didn't find anything. Could anybody give me any advice? Thanks
Before trying it yourself, I strongly recommend backing up your user profile.
Say the name of your Writer template file is MyTemplate.ott
First, and I assume you can do this programmatically, copy MyTemplate.ott into the template folder of your user profile
Code: Select all
....\OpenOffice.org\3\user\template\
Since this changes the Configuration data, it is normally necessary to restart Office before the changes take effect.
Code: Select all
Sub SetDefaultWriterTemplate()
Dim sNodePath As String
Dim oCP, oCUA
Dim TextFactory
Dim DefaultTemplateName As String
DefaultTemplateName = "MyTemplate.ott"
sNodePath = "/org.openoffice.Setup/Office/Factories"
Dim aProps(0) As New com.sun.star.beans.PropertyValue
oCP = CreateUnoService("com.sun.star.configuration.ConfigurationProvider" )
aProps(0).Name = "nodepath"
aProps(0).Value = sNodePath
oCUA = oCP.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aProps )
TextFactory = oCua.getByName("com.sun.star.text.TextDocument")
TextFactory.ooSetupFactoryTemplateFile = "$(user)/template/" & DefaultTemplateName
TextFactory.ooSetupFactorySystemDefaultTemplateChanged = True
oCUA.commitChanges()
End Sub
Apache OpenOffice 4.1.1
Windows XP
Windows XP