Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Connecting to Openoffice API in Matlab with actxserver

134 views
Skip to first unread message

Richard

unread,
Jul 30, 2009, 1:26:03 PM7/30/09
to
I thought I'd try to put my own functions together that would connect to openoffice using their API and activexserver (similarly to how saveppt.m connects to powerpoint). In theory, it should be possible to create writer, impress, etc... documents.

At this point I've run in to a wall.

Here's what I do:
objServiceManager = actxserver('com.sun.star.ServiceManager')
objDesktop=invoke(objServiceManager,'createInstance','com.sun.star.frame.Desktop')
objDocument = invoke(objDesktop,'private:factor/swriter','_blank',0,[])

The last line causes an error that's says
??? Invoke Error: Unknown name or named argument

Here's some example VB code that is given as an example at http://udk.openoffice.org/common/man/tutorial/office_automation.html. Supposedly this VB codes creates a writer document and inserts some text.

'The service manager is always the starting point
'If there is no office running then an office is started up
Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
'Create the Desktop
Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")
'Open a new empty writer document
Dim args()
Set objDocument= objDesktop.loadComponentFromURL("private:factory/swriter",_
"_blank", 0, args)
'Create a text object
Set objText= objDocument.getText
'Create a cursor object
Set objCursor= objText.createTextCursor
'Inserting some Text
objText.insertString objCursor, "The first line in the newly created text document."&_
vbLf, false

Yair Altman

unread,
Jul 31, 2009, 3:15:18 AM7/31/09
to
"Richard" <lesri...@PleaseNoSpam.gmail.com> wrote in message
<snip>

> objDocument = invoke(objDesktop,'private:factor/swriter','_blank',0,[])
>
> The last line causes an error that's says
> ??? Invoke Error: Unknown name or named argument
...

> Set objDocument= objDesktop.loadComponentFromURL("private:factory/swriter",_
> "_blank", 0, args)


If you'll look closely you'll see that you tried to invoke the first argument as the function name, which of course results in an error. Instead:

objDocument = invoke(objDesktop, 'loadComponentFromURL', 'private:factor/swriter','_blank',0,[])

Yair Altman
http://UndocumentedMatlab.com

Richard

unread,
Jul 31, 2009, 9:45:05 AM7/31/09
to
Thanks Yair,

You're right--I was wondering why the error message was a little different then last time I tried. Thanks for catching that. So with the corrected code:

objServiceManager = actxserver('com.sun.star.ServiceManager')
objDesktop=invoke(objServiceManager,'createInstance','com.sun.star.frame.Desktop')

objDocument=invoke(objDesktop,'loadComponentFromURL','private:factor/swriter','_blank',0,[])

I actually get the following error:
??? Error: Type mismatch, argument 1

I don't know if it doesn't like the empty argument or which one.

"Yair Altman" <altma...@gmailDEL.comDEL> wrote in message <h4u5m6$nag$1...@fred.mathworks.com>...

Donn Shull

unread,
Jul 31, 2009, 12:19:01 PM7/31/09
to
"Richard" <lesri...@PleaseNoSpam.gmail.com> wrote in message <h4ush1$lbq$1...@fred.mathworks.com>...

Hi Richard,

You might try using '' (ie an empty string) instead of [] for the empty args argument.

Good Luck,

Donn

Marcus Ekholm

unread,
Apr 13, 2016, 7:57:09 AM4/13/16
to
"Donn Shull" <donn.shul...@aetoolbox.com> wrote in message <h4v5hl$5be$1...@fred.mathworks.com>...
Has anyone figured this one out? In the original post argument 1 was incorrect. factor should be factory. But fixing that doesn't help. There's still something wrong with argument 1. Error is "Type mismatch, argument 1"
Searching around on internet doesn't yield much.

objServiceManager = actxserver('com.sun.star.ServiceManager');
objDesktop=invoke(objServiceManager,'createInstance','com.sun.star.frame.Desktop');
objDocument=invoke(objDesktop,'loadComponentFromURL','private:factory/swriter','_blank',0,'');

/Marcus

yerlan.ch...@gmail.com

unread,
Jul 1, 2020, 11:36:41 AM7/1/20
to
среда, 13 апреля 2016 г., 13:57:09 UTC+2 пользователь Marcus Ekholm написал:
Instead of '' or [] put {} as an empty args argument.
0 new messages