Thread Subject: Connecting to Openoffice API in Matlab with actxserver

Subject: Connecting to Openoffice API in Matlab with actxserver

From: Richard

Date: 30 Jul, 2009 17:26:03

Message: 1 of 4

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

Subject: Connecting to Openoffice API in Matlab with actxserver

From: Yair Altman

Date: 31 Jul, 2009 07:15:18

Message: 2 of 4

"Richard" <lesricains@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
 

Subject: Connecting to Openoffice API in Matlab with actxserver

From: Richard

Date: 31 Jul, 2009 13:45:05

Message: 3 of 4

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" <altmanyDEL@gmailDEL.comDEL> wrote in message <h4u5m6$nag$1@fred.mathworks.com>...
> "Richard" <lesricains@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
>

Subject: Connecting to Openoffice API in Matlab with actxserver

From: Donn Shull

Date: 31 Jul, 2009 16:19:01

Message: 4 of 4

"Richard" <lesricains@PleaseNoSpam.gmail.com> wrote in message <h4ush1$lbq$1@fred.mathworks.com>...
> 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" <altmanyDEL@gmailDEL.comDEL> wrote in message <h4u5m6$nag$1@fred.mathworks.com>...
> > "Richard" <lesricains@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
> >

Hi Richard,

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

Good Luck,

Donn

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
openoffice Richard 30 Jul, 2009 16:42:47
visual basic Richard 30 Jul, 2009 16:42:47
activexserver Richard 30 Jul, 2009 16:42:47
rssFeed for this Thread

Contact us at files@mathworks.com