wie kann ich feststellen, ob der Cursor aktuell innerhalb einer Tabelle steht und in welcher Zelle, falls ja ...
Hintergrund: ich möchte per Makro ein Eingabefeld einfügen und bekomme, sobald der Cursor innerhalb einer Tabellenzeile steht eine Exception innerhalb des "normalen" Textbereichs ist alles OK.
Mein unaufgeräumter Beispielcode
Code: Alles auswählen
private void insertTextField(XComponentContext xCurrentComponent, String fieldName, String fieldValue, String fieldHelp) throws BootstrapException, Exception
{
Object desktop = xCurrentComponent.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xCurrentComponent);
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop) ;
XComponent aCurrentComponent = xDesktop.getCurrentComponent();
XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, aCurrentComponent);
XText xDocText = xTextDocument.getText();
XMultiServiceFactory xDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, xTextDocument);
// die aktuelle Position im Dokument besorgen ...
XController xController = xTextDocument.getCurrentController();
XTextViewCursorSupplier xTextViewCursorSupplier = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController);
XTextViewCursor xDocTextCursor = xTextViewCursorSupplier.getViewCursor();
// etwas fuer die Properties bereitstellen ...
XPropertySet inputTextFieldProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xDocFactory.createInstance( "com.sun.star.text.TextField.Input"));
inputTextFieldProps.setPropertyValue("Hint", fieldName);
inputTextFieldProps.setPropertyValue("Content", fieldValue);
inputTextFieldProps.setPropertyValue("Help", fieldHelp );
XTextContent inputFieldTextContent = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, inputTextFieldProps );
XSelectionSupplier xSelectionSupplier = (XSelectionSupplier) UnoRuntime.queryInterface(XSelectionSupplier.class, xController);
XInterface xInterface = (XInterface) UnoRuntime.queryInterface(XInterface.class, xSelectionSupplier.getSelection());
XTextRange xTextRange = (XTextRange)UnoRuntime.queryInterface(XTextRange.class, xInterface);
XIndexAccess xIndexAccess = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class,xInterface);
xDocText.insertTextContent(xDocTextCursor, inputFieldTextContent, false);
}
Code: Alles auswählen
Exception in thread "AWT-EventQueue-0" com.sun.star.uno.RuntimeException: text interface and cursor not related
In Basic scheint es ja die Möglichkeit zu geben, festzustellen, ob der Cursor in einer Tabelle steht, irgendwo gefundener Code:
Code: Alles auswählen
oVCurs = ThisComponent.getCurrentController().getViewCursor()
REM Is the cursor in a table?
If IsEmpty(oVCurs.TextTable) Then
Print "The cursor is NOT in a table"
Exit Sub
End If
Hilfe!!!