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

Selection in TextTables

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


Joined: 06 Mar 2006
Posts: 29
Location: Poland

PostPosted: Fri Mar 10, 2006 2:02 am    Post subject: Selection in TextTables Reply with quote

Hello everyone.
I've got problem with selection in text tables. I obtain the selection in this way:

Code:

    XSelectionSupplier xselectionsupplier =( XSelectionSupplier ) UnoRuntime.queryInterface(
                        XSelectionSupplier.class, xcontroller );
           
    Object objectSelection = xselectionsupplier.getSelection();
           
    XServiceInfo xserviceinfo = ( XServiceInfo )UnoRuntime.queryInterface( XServiceInfo.class, objectSelection );


When selection is in table there are three possibilities:
1. xserviceinfo supports XTextTableCursor - I don't know how to check which cells are selected
2. xserviceinfo supports XTextRange
3. xserviceinfo supports XTextRanges - I do something like this:

Code:


XIndexAccess xIA = ( XIndexAccess )UnoRuntime.queryInterface(XIndexAccess.class, objectSelection );

xTR = ( XTextRange )UnoRuntime.queryInterface( XTextRange.class, xIA.getByIndex( 0 ) );

XEnumerationAccess xParaAccess = (XEnumerationAccess) UnoRuntime.queryInterface( XEnumerationAccess.class, xTR );

while( xParaEnum.hasMoreElements() )
{
XServiceInfo xInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xParaEnum.nextElement() );


if ( !xInfo.supportsService ( "com.sun.star.text.TextTable" ) )
{/*...*/}
else
{
XCellRange xCR = (XCellRange)UnoRuntime.queryInterface( XCellRange.class, xInfo );
}
};


In xCR is not only selection, but the whole table. How to check which cells are selected?

Help me please.
Thanks.
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Fri Mar 10, 2006 5:33 am    Post subject: Reply with quote

Perhaps this Basic code will help. The range name consists of the upper left and lower right cells of the selection in the format A1:B2. (My efforts to select a range that is not a rectangle like A1,A2 & B1 have not been successful and if you can't do that then all cells are known from the range name.)
Code:
Sub Main
oDoc = thisComponent
oRange = oDoc.getCurrentSelection()
If oRange.supportsService("com.sun.star.text.TextTableCursor") then
  Print oRange.getRangeName()
 Else Print "No text table range has been selected."
EndIf
End Sub
Back to top
View user's profile Send private message
GenezypKapen
General User
General User


Joined: 06 Mar 2006
Posts: 29
Location: Poland

PostPosted: Fri Mar 10, 2006 6:10 am    Post subject: Reply with quote

It may help, but I still don't know one thing. If I call getRangeName() I will get the range name (something like A3:B3), but from which table? In a Writer document can exist several tables.
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Fri Mar 10, 2006 10:47 am    Post subject: Reply with quote

The code I posted assumes a range of cells is selected and as I don't think it is possible to have cells selected in two different tables I'm not sure how the 2nd line of code could get anything but the table where the cells are in fact selected.
Back to top
View user's profile Send private message
AlicVB
General User
General User


Joined: 15 Feb 2007
Posts: 10

PostPosted: Thu Sep 13, 2007 11:28 am    Post subject: Reply with quote

Quote:
but from which table? In a Writer document can exist several tables.


For this, I use something like this :
Code:
ThisComponent.CurrentControler.ViewCursor.TextTable


AlicVB
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