[Solved] New doc from template with loadComponentFromURL()
Posted: Tue Sep 09, 2014 4:07 pm
Hello
I'm new to OO and just getting my hands dirty a little bit to see if we could use is professionally. We think of producing reports with OpenOffice.
What I want to do is the following: Cause an application to launch OpenOffice and make a new document from a OpenOffice-template. I have OpenOffice 4.1.0 on Windows 7 and I have the template file ready. Currently I try to do that in Excel VBA editor. I also tried it with a python interpreter with no luck either.
Herer's the code (VBA) that doesn't work:
The messagebox shows "AsTemplate, True", as one would expect. But on the last line, where I loadComponentFromURL it throws this error:
[automation bridge]com.sun.star.script.CannotConvertException in UnoConversionUtilities<T>::variantToAny! Message: value is not of same or derived type!
I suspect, that there is something wrong with the datatype of oFileProperties, but I just can't fix it
Any ideas anyone? I keep trying with python so long
I'm new to OO and just getting my hands dirty a little bit to see if we could use is professionally. We think of producing reports with OpenOffice.
What I want to do is the following: Cause an application to launch OpenOffice and make a new document from a OpenOffice-template. I have OpenOffice 4.1.0 on Windows 7 and I have the template file ready. Currently I try to do that in Excel VBA editor. I also tried it with a python interpreter with no luck either.
Herer's the code (VBA) that doesn't work:
Code: Select all
' Compute Template path
templatePath = "c:\Users\mat\Desktop\Report_OoTest.ots"
templatePath = Replace(templatePath, "\", "/")
templatePath = Replace(templatePath, ":", "|")
templatePath = "file:///" & templatePath
' Create service manager
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
' Do some magic
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
set oFileProperties(0) = oServiceManager.Bridge_GetStruct("com.sun.star.beans.NamedValue")
oFileProperties(0).Name = "AsTemplate"
oFileProperties(0).Value = True
msgbox oFileProperties(0).Name & ", " & oFileProperties(0).Value
' Make new file from templatefile
Set oDoc = oDesktop.loadComponentFromURL(templatePath, "_blank", 0, oFileProperties)
[automation bridge]com.sun.star.script.CannotConvertException in UnoConversionUtilities<T>::variantToAny! Message: value is not of same or derived type!
I suspect, that there is something wrong with the datatype of oFileProperties, but I just can't fix it
Any ideas anyone? I keep trying with python so long