One last thing on MS Word in Java: replacing text...

Trying to solve my issue on how to replace placeholders inside a MS Word in Java, I choose to replace texts and avoid the use of document properties. BUT!!!

I learned that you can't use prefix/suffix like in template engine (e.g. ${myproperty}). Indeed, in order to replace texts using Apache POI in Java, you need to cycle on objects called XWPFRun obtained by XWPFParagraph(s) found inside header/footers/document/tables/etc... The problem is that if your placeholder is named ${myproperty} you have 3 XWPFRun:

  1. ${
  2. myproperty
  3. }
and replacing theme is pretty "hard"!

Actually, the solution is to avoid any symbol in the placeholders (e.g. myproperty instead of ${myproperty}). In order to avoid replacements on texts that do not need to change, I choose to use a textual prefix (e.g. vodafonecanvass.myproperty) in my plugin.
Stay tuned for the next push!

Comments

Popular posts from this blog