I'm making an extension in java for OpenOffice and I need to do something on each character.
On word I've been able to do it using :
foreach item in doc.characters
Is there something similar in OpenOffice Java API?
I'm making an extension in java for OpenOffice and I need to do something on each character.
On word I've been able to do it using :
foreach item in doc.characters
Is there something similar in OpenOffice Java API?
Here is a simple example that counts all characters in a document.
xText = xTextDocument.getText();
XTextCursor xTextCursor = xText.createTextCursorByRange(xText.getStart());
int num_chars = 0;
while (xTextCursor.goRight((short)1, false)) { num_chars++; }
System.out.println("Found " + num_chars + " characters.");
However if there are objects such as tables or frames, then a single text cursor will not work. Using the view cursor handles tables and frames but is much slower. See section 7.14.2 of Andrew Pitonyak's macro document for more complete examples.
Another approach is to enumerate all text content in the document, as in section 7.16.3 of Andrew's document. Related information for Java is also in the Dev guide. Then for each text portion, iterate over it by creating a text cursor, which should be reasonably fast.