| View previous topic :: View next topic |
| Author |
Message |
GenezypKapen General User


Joined: 06 Mar 2006 Posts: 29 Location: Poland
|
Posted: Fri Mar 10, 2006 2:02 am Post subject: Selection in TextTables |
|
|
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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8976 Location: Lexinton, Kentucky, USA
|
Posted: Fri Mar 10, 2006 5:33 am Post subject: |
|
|
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 |
|
 |
GenezypKapen General User


Joined: 06 Mar 2006 Posts: 29 Location: Poland
|
Posted: Fri Mar 10, 2006 6:10 am Post subject: |
|
|
| 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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8976 Location: Lexinton, Kentucky, USA
|
Posted: Fri Mar 10, 2006 10:47 am Post subject: |
|
|
| 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 |
|
 |
AlicVB General User

Joined: 15 Feb 2007 Posts: 10
|
Posted: Thu Sep 13, 2007 11:28 am Post subject: |
|
|
| 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 |
|
 |
|