I'm trying to replace a word inside a Paragraph.
Explaining the context, i'm inserting Texts (that have HTML inside the Text Variable) into a Paragraph, from my Database.
- Code: Select all
TextSelection position = document.FindString("textPositionIntoWordDocument", true, true);
TextRange range = position.GetAsOneRange();
Paragraph paragraph = range .OwnerParagraph;
paragraph .Text = String.Empty;
paragraph .AppendHTML(stringWithHTML);
And I want to replace a word inside that Text that was inserted before, called {customerName}
I'm trying this, but this will replace all my HtmlText inserted.
- Code: Select all
TextSelection[] positions = document.FindAllString("{customerName}", true, true);
foreach (var actualPosition in positions)
{
TextRange range= actualPosition .GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
paragraph .Text = Customer.Name;
}
And the worst, if my inserted text have a HTML attribute, like a Header Text (<h1>), when I "replace", I lose that, and I dont want it!
Example:
String stringHtml = "<h1>Hello {customerName}</h1>";
When I replace:
Kevinka999
What I want
Hello Kevinka999
If it’s not asking too much, simplify max u can the code so I can understand better how it works
Thanks a lot!