We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replace with multiple Lines (\n)

Hello,


I try to search an replace different Texts in a Word-Document (.doc).
For that i Use Java 5 and Aspose.Words for Java 4 Beta (saveToPdf-Function is needed afterwards)

\n has to be a new Line

For Example:

$$Name$$ -> Mr. Sherlock Holmes
$$Adress$$ -> 221b Baker Street \n London \n England

Theres no function in the DocumentBuilder like moveTo(TheStringIWantToMoveTo)

Also when i tried to use

doc.getRange().replace("$$Adress$$", “221b Baker Street \n London \n England”, false, false);

Theire were no new Lines in the Document. Instead the new Lines were displayed as Squares in the Word-Document (see test_test.doc)

Do you have an Idea and maybe a Code-Sample how i could do that?

thanks

oh forgot to add


Is it also somehow Possible to Format the Replaced Text? Make Parte of it Bold, Larger or change the Color to Red?

example

$$Adress$$ -> 221b Baker Street \n London \n England (from above)
to
$$Adress$$ -> 221b Baker Street \n London \n England (or so)

Thougt it might be Possible to jump with the DocumentBuilder and use writeLine or so there and delete the $$*$$ and go somehow to the next place

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I think, in your case you should use ReplaceEvaluator:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/com/aspose/words/range.html#replace(java.util.regex.Pattern,%20com.aspose.words.ReplaceEvaluator,%20boolean)

In ReplaceEvaluator you can use Documentbuilder, so you can specify formatting of the replacement.

Regarding \n characters, you can try replacing \n character in the replacement string with com.aspose.words.ControlChar.LINE_BREAK.

Best regards,