Not able to read special characters by XWordCursor.getString
Posted: Thu Apr 09, 2020 5:29 am
Hi All,
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
the output of the code is for the attached document is
the expected output should be
I found a similar thread also http://openoffice.2283327.n4.nabble.com ... 11431.html but not able to get much information out of it.
Any help or clue is appreciated, thanks
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
employeenoCode: Select all
TestingFirstWord
Hello
test
${name}
${employeeno}Any help or clue is appreciated, thanks