Venkatesh Goud Venkatesh Goud - 1 month ago 18
Java Question

How should i replace the string in word document with another string using poi?

i new to poi.i have a requirement to develop and edit the word document using poi.please send any sample examples for above question.

Answer

XWPF: See part 1 and 2 of my blog post on POI, here: http://tkgospodinov.com/writing-microsoft-word-documents-in-java-with-apache-poi/. You can use XWPFDocument#setParagraph to replace a whole paragraph with POI, so you can get the paragraph where you want to replace text, and create a new paragraph with the result and set it in place of the original. Keep in mind that this is new API since 3.7-beta2. I know it's a little convoluted, but currently that is the only way to accomplish that.