[Solved] New doc from template with loadComponentFromURL()

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] New doc from template with loadComponentFromURL()

Postby Mat » 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:

Code: Select all   Expand viewCollapse view
' 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)


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 :crazy:

Any ideas anyone? I keep trying with python so long
Last edited by Hagar Delest on Wed Sep 10, 2014 9:41 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.0 on Windows 7 (at work for testing), some LibreOffice on openSUSE 13.1 at home
Mat
 
Posts: 2
Joined: Tue Sep 09, 2014 3:49 pm
Location: Switzerland

Re: New document from template with loadComponentFromURL()

Postby FJCC » Tue Sep 09, 2014 6:17 pm

Try
Code: Select all   Expand viewCollapse view
set oFileProperties(0) = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")

In the help I see
loadComponentFromURL
::com::sun::star::lang::XComponent
loadComponentFromURL( [in] string URL,
[in] string TargetFrameName,
[in] long SearchFlags,
[in] sequence< ::com::sun::star::beans::PropertyValue > Arguments )
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7752
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: New document from template with loadComponentFromURL()

Postby Mat » Wed Sep 10, 2014 4:51 pm

Thanks for the quick reply FJCC!
Using a PropertyValue instead of a NamedValue did the trick.
Combining code snippets without much understanding can provide a jump start, but also has it's disadvantages...
Thanks and greetings!
OpenOffice 4.1.0 on Windows 7 (at work for testing), some LibreOffice on openSUSE 13.1 at home
Mat
 
Posts: 2
Joined: Tue Sep 09, 2014 3:49 pm
Location: Switzerland


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest