You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by Semen Gubarev <mn...@gmail.com> on 2014/10/02 10:21:27 UTC

create instance of XTextTable service c++

Hello,
I trying to create simple executable application for connect to OpenOffice
4.1.1 and create table in writer.
I successfully create connection with OpenOffice and do some work (like
insert texts), but I can't create a table.
I have a problem with creation "com.sun.star.text.XTextTable" interface

some example of cpp code:
Reference< XMultiServiceFactory > xMutiServiceFactory =
ooConnect("uno:socket,host=localhost,port=2002;urp;
StarOffice.ServiceManager");

    Reference< XInterface > _xInterface = xMutiServiceFactory->
createInstance(OUString::createFromAscii("com.sun.star.text.XTextTable"));
    if (!_xInterface.is()) {         //here I always get false! (also I
tring to get "com.sun.star.text.TextTable" the same truble
        return 0;
    }

what can be wrong?

Re: create instance of XTextTable service c++

Posted by Jürgen Schmidt <jo...@gmail.com>.
On 02/10/14 10:21, Semen Gubarev wrote:
> Hello,
> I trying to create simple executable application for connect to OpenOffice
> 4.1.1 and create table in writer.
> I successfully create connection with OpenOffice and do some work (like
> insert texts), but I can't create a table.
> I have a problem with creation "com.sun.star.text.XTextTable" interface
> 
> some example of cpp code:
> Reference< XMultiServiceFactory > xMutiServiceFactory =
> ooConnect("uno:socket,host=localhost,port=2002;urp;
> StarOffice.ServiceManager");
> 
>     Reference< XInterface > _xInterface = xMutiServiceFactory->
> createInstance(OUString::createFromAscii("com.sun.star.text.XTextTable"));
>     if (!_xInterface.is()) {         //here I always get false! (also I
> tring to get "com.sun.star.text.TextTable" the same truble
>         return 0;
>     }
> 
> what can be wrong?
> 

Do you know the Developers Guide? I recommend the DevGuide [1] as
reference and to get some basic knowledge about the API. You can also
check the SDK and the samples in the SDK. There exist Java samples that
insert a table in a text document.

The problem here is that some services are only available in the context
of a text document and that a text document have it own service factory.
The easiest way is to check the samples in the SDK.

Juergen

[1] https://wiki.openoffice.org/wiki/Documentation/DevGuide

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org


Re: create instance of XTextTable service c++

Posted by Semen Gubarev <mn...@gmail.com>.
Thanks for reply!
I just want to clarify this moment for other who need to create instance of
XTextTable

//... we have already connection with OpenOffice ... and we have Reference
<XDesktop> xDesktop instance

//read some document file
OUString sDocURL;
osl::FileBase::getFileURLFromSystemPath(OUString::createFromAscii("D:\\W\\OpenOfficeTest\\Test2\\Debug\\test.odt"),
sDocURL);
Reference< XComponent > xComponent = Reference<XComponentLoader>(xDesktop,
UNO_QUERY)->loadComponentFromURL(
sDocURL,
OUString::createFromAscii("_default"),
0,
Sequence< ::com::sun::star::beans::PropertyValue>());

//and create instance of XTextTable service
Reference <XTextTable> xTextTable = Reference<XTextTable> ((Reference
<XMultiServiceFactory>(xComponent,
UNO_QUERY))->createInstance(OUString::createFromAscii("com.sun.star.text.TextTable")),
UNO_QUERY);
//check is xTextTable is available
if (!xTextTable.is()) {
  return 0;
}

I just write the first time, so I do not undestand do I need to send the
example of finished code if I get success with my issue or not.

2014-10-02 14:53 GMT+06:00 Miklos Vajna <vm...@collabora.co.uk>:

> Hi Semen,
>
> On Thu, Oct 02, 2014 at 02:21:27PM +0600, Semen Gubarev <mn...@gmail.com>
> wrote:
> > I trying to create simple executable application for connect to
> OpenOffice
> > 4.1.1 and create table in writer.
> > I successfully create connection with OpenOffice and do some work (like
> > insert texts), but I can't create a table.
> > I have a problem with creation "com.sun.star.text.XTextTable" interface
> >
> > some example of cpp code:
> > Reference< XMultiServiceFactory > xMutiServiceFactory =
> > ooConnect("uno:socket,host=localhost,port=2002;urp;
> > StarOffice.ServiceManager");
> >
> >     Reference< XInterface > _xInterface = xMutiServiceFactory->
> >
> createInstance(OUString::createFromAscii("com.sun.star.text.XTextTable"));
> >     if (!_xInterface.is()) {         //here I always get false! (also I
> > tring to get "com.sun.star.text.TextTable" the same truble
> >         return 0;
> >     }
> >
> > what can be wrong?
>
> com.sun.star.text.TextTable is the right form, see e.g.
>
> http://opengrok.libreoffice.org/xref/core/scripting/examples/python/pythonSamples/TableSample.py
>
> The trick is that you have to call the createInstance() method on the
> created Writer component, not on the generic xMutiServiceFactory, since
> that one has no idea in what document the table would created, so it
> doesn't create anything. ;-)
>
> Regards,
>
> Miklos
>



-- 
Best Regards
    Губарев Семен