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 <vmik...@collabora.co.uk>:

> Hi Semen,
>
> On Thu, Oct 02, 2014 at 02:21:27PM +0600, Semen Gubarev <mnog...@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
    Губарев Семен

Reply via email to