The Problem is, that you can only replaceText for single runs. But what
happens, if your whole word (for example word_to_replace ') is not placed in
one run, but in more than one run. Then, the API don't know your word and
can not replace it.

I had to build a workaround and saved in which run the 'word_to_replace'
begins and in which run it ends (for example in run 10 it begins and in run
13 it ends). 
=> So I inserted the 'new_text' inside the first run 10 and for the
following 11-13 I inserted an empty string "".

When you want to adjust the problem insert the text 'text_to_replace' in a
simple docx-file. But do not insert it with a complete insertion like a)
insert 'text_to_replace', b) save docx, c) replaceText. 
=> Correct your word, replace single characters of 'text_to_replace' with
MS-Word and save it again. Then try to replace the Text
=> Or insert your word like this "text to replace" and then use MS-Word to
insert "_" instead of the " ". Then try to replace the Text

By saving the doc once more after changing characters, MS-Word sometimes
creates new runs so that your algorithm can't work. But that is only one
possibility how it may happen...

You only have to insert your word in different ways and do a little 'try and
error' till the api is not able to identify your word in a single run.

best regards

Thomas

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/run-text-replaceAll-old-value-new-value-NOT-STABLE-tp5038681p5055153.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to