OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

TableText: create a table in a writer document (OpenOffice3)

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
professor_rumsdiegeige2
General User
General User


Joined: 09 Nov 2008
Posts: 8

PostPosted: Mon Nov 10, 2008 10:00 am    Post subject: TableText: create a table in a writer document (OpenOffice3) Reply with quote

Hello!

I try to create a text table in a text document using OpenOffice 3 and the corresponding SDK and C#.

To do this, I try the following:
Code:

private XComponentContext m_xContext;
private XComponent m_Doc;
private XMultiServiceFactory mxMSFactory;
private XTextDocument mxDocument;
private XTextTable mxtable;
// ...
m_xContext = uno.util.Bootstrap.bootstrap();

mxMSFactory = (XMultiServiceFactory)m_xContext.getServiceManager();
// ...
XComponentLoader aLoader = (XComponentLoader)mxMSFactory.createInstance("com.sun.star.frame.Desktop");
m_Doc = aLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0,
                new unoidl.com.sun.star.beans.PropertyValue[0]);
// ...


Until here, no problem, everything works fine. But then I try the text table:

Code:

mxtable = (XTextTable)(mxMSFactory.createInstance("com.sun.star.text.TextTable"));



and the result is that mxtable is always null.

Has anybody an idea why?
If I try another type, say com.sun.star.text.TextRange, it works, so it is a specific TextTable problem. Is this one perhaps removed in the new OpenOffice 3?

Many thanks!
Sabine Lorentz
Back to top
View user's profile Send private message
vitcaro
OOo Advocate
OOo Advocate


Joined: 20 Feb 2007
Posts: 256
Location: Italy

PostPosted: Mon Nov 10, 2008 10:48 am    Post subject: Reply with quote

Must use document service factory in place of Multi Service Factory

Code:

// get internal service factory of the document
XMultiServiceFactory xWriterFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(
XMultiServiceFactory.class, xWriterComponent);
// insert TextTable and get cell text, then manipulate text in cell
Object table = xWriterFactory.createInstance("com.sun.star.text.TextTable");
XTextContent xTextContentTable = (XTextContent)UnoRuntime.queryInterface(
XTextContent.class, table);
Back to top
View user's profile Send private message
professor_rumsdiegeige2
General User
General User


Joined: 09 Nov 2008
Posts: 8

PostPosted: Mon Nov 10, 2008 11:11 am    Post subject: Reply with quote

Thank you for your quick reply.

Just got a question, because I'm not really familiar with Java (I assume your code is in Java, isn't it?)

In C#, this "UnoRuntime.queryInterface" doesn't exist, you have to cast the objects instead. To do that, I need to know of what type this "xWriterComponent" in your code
Code:

XMultiServiceFactory xWriterFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(
XMultiServiceFactory.class, xWriterComponent);

is...

Thank you again.
Regards
Sabine Lorentz
Back to top
View user's profile Send private message
vitcaro
OOo Advocate
OOo Advocate


Joined: 20 Feb 2007
Posts: 256
Location: Italy

PostPosted: Mon Nov 10, 2008 12:53 pm    Post subject: Reply with quote

I have no practice of C#, but from your code I can suggest the following line:

Code:

private XMultiServiceFactory xWriterFactory;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group