Hi
I'm working with openoffice writer documents. I'm writing a plugin for inserting scripts in the current cursor position.
When I have plain text in my document, this simple code works:
private void writeSimple(String htmlText) throws Exception {
com.sun.star.view.XSelectionSupplier xSelSupplier =
(com.sun.star.view.XSelectionSupplier)UnoRuntime.queryInterface(
com.sun.star.view.XSelectionSupplier.class, document.getCurrentController() );
Object oSelection = xSelSupplier.getSelection();
com.sun.star.lang.XServiceInfo xServInfo =
(com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
com.sun.star.lang.XServiceInfo.class, oSelection );
com.sun.star.text.XTextRange selectedRange = null;
if ( xServInfo.supportsService("com.sun.star.text.TextRanges") ){
com.sun.star.container.XIndexAccess xIndexAccess =
(com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
com.sun.star.container.XIndexAccess.class, oSelection);
selectedRange = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, xIndexAccess.getByIndex(0));
}
XMultiServiceFactory multiServiceFactory =
(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
Object xObject = multiServiceFactory.createInstance("com.sun.star.text.textfield.Input");
XPropertySet propertySet =
(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xObject);
propertySet.setPropertyValue("Content", htmlText);
propertySet.setPropertyValue("Hint", "JavaScript");
XTextContent xTextContent =
(XTextContent)UnoRuntime.queryInterface(XTextContent.class, xObject);
document.getText().insertTextContent(selectedRange, xTextContent, true);
}
The problem remains for the XTextTables. I can get the selected text of a table cell, but I can not replace it.
When the active selection is just a piece of text within a cell of a table the selection contains a sequence of
XTextRanges but the below code does not work
document.getText().insertTextContent(selectedRange, xTextContent, true);
Can some one help me out.
Regards,
Fabio
[Solved] Insert text at current cursor position of TextTable
[Solved] Insert text at current cursor position of TextTable
Last edited by Hagar Delest on Thu Feb 14, 2013 9:46 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
openoffice 3.4.1, Windows 7
Re: Insert text in the current cursor position of a TextTabl
Ok solved!
The wrong code is the line:
document.getText().insertTextContent(selectedRange, xTextContent, true);
the right one is
selectedRange.getText().insertTextContent(selectedRange, xTextContent, true);
Thanks!
The wrong code is the line:
document.getText().insertTextContent(selectedRange, xTextContent, true);
the right one is
selectedRange.getText().insertTextContent(selectedRange, xTextContent, true);
Thanks!
openoffice 3.4.1, Windows 7