I am successfully able to read word by word from a Docx file using below code snippet, the problem is all special character like ($,{ , }) are ignored by XWordCursor.getString
Code: Select all
XComponent xComp = xCompLoader.loadComponentFromURL(
sUrl, "_blank", 0, propertyValues);
com.sun.star.text.XTextDocument xTextDocument =
(com.sun.star.text.XTextDocument) UnoRuntime.queryInterface(
com.sun.star.text.XTextDocument.class, xComp);
XText xText = xTextDocument.getText();
XSimpleText xSimpleText = UnoRuntime.queryInterface(
XSimpleText.class, xText);
XTextCursor xTextCursor = xSimpleText.createTextCursor();
xTextCursor.gotoEnd(true);
XTextRange xTextRange = UnoRuntime.queryInterface(
XTextRange.class, xTextCursor);
String sString = xTextRange.getString();
XTextCursor textCursor = xTextRange.getText().createTextCursorByRange(xTextRange.getStart());
XWordCursor wordCursor = (XWordCursor)
UnoRuntime.queryInterface(XWordCursor.class, textCursor);
wordCursor.gotoStart(false); // go to start of text
int wordCount = 0;
String currWord;
do {
wordCursor.gotoEndOfWord(true);
currWord = wordCursor.getString();
if (currWord.length() > 0) {
// System.out.println("<" + currWord + ">");
wordCount++;
System.out.println(currWord);
}
} while( wordCursor.gotoNextWord(false));
Code: Select all
TestingFirstWord
Hello
test
name
employeeno
Code: Select all
TestingFirstWord
Hello
test
${name}
${employeeno}
Any help or clue is appreciated, thanks