[Solved] Insert text at current cursor position of TextTable

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] Insert text at current cursor position of TextTable

Postby fabio » Thu Feb 14, 2013 1:15 pm

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
Last edited by Hagar Delest on Thu Feb 14, 2013 9:46 pm, edited 1 time in total.
Reason: tagged [Solved].
openoffice 3.4.1, Windows 7
fabio
 
Posts: 2
Joined: Thu Feb 14, 2013 12:19 pm

Re: Insert text in the current cursor position of a TextTabl

Postby fabio » Thu Feb 14, 2013 4:48 pm

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!
openoffice 3.4.1, Windows 7
fabio
 
Posts: 2
Joined: Thu Feb 14, 2013 12:19 pm


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest