Not completely.
For Each sect As WSection In document.Sections
For Each par As WParagraph In sect.Paragraphs
If par.GetStyle.Name.ToString.ToLower = sStyle.ToLower Then
Dim chara As WCharacterFormat = New WCharacterFormat(document)
chara.UnderlineStyle = UnderlineStyle.Single
chara.TextColor = Drawing.Color.Red
For Each item As ParagraphItem In par.Items
If item.EntityType = EntityType.TextRange Then
Dim trange As WTextRange = TryCast(item, WTextRange)
If trange.Text.Contains(txtSearch.Text) Then
' Replace the txtSearch.text by txtReplace.text
' And apply red-underline
trange.ApplyCharacterFormat(chara)
End If
End If
Next item
End If
Next
Next
This change the style of a completely line and not from the search item (what can be more than 1 word, but also 1 letter)
And I have to change the search-item by the replace-item. But this can be done by WParagraph.Replace, if this will not mess up the character-format that I just have done.
>Hi Aart,
Thank you for your interest in Syncfusion products.
In paragraph object you can find only string Replace method and this method not possible to have replacing the TextBodypart. Since TextBodyPart is collection of body items.
If you want to find and replace the specific word. Please use the below code snippet and if you want to set more than one character style then please create a new characterFormat style by using the WCharacterFormat and then define new styles and assign this format to the specified TextRange object as we have suggested in your Direct trac incident.
[VB]
Dim chara As WCharacterFormat = New WCharacterFormat(document)
chara.UnderlineStyle = UnderlineStyle.Dotted
chara.FontSize = 18.0F
chara.TextBackgroundColor = Color.Blue
Dim document As WordDocument = New WordDocument("..\..\Template.doc")
For Each ent As Entity In document.ChildEntities
If TypeOf ent Is WSection Then
Dim section As WSection = TryCast(ent, WSection)
For Each paragraph As WParagraph In section.Body.Paragraphs
For Each item As ParagraphItem In paragraph.Items
If item.EntityType = EntityType.TextRange Then
Dim range As WTextRange = TryCast(item, WTextRange)
If range.Text.Contains("DocIO") Then
range.ApplyCharacterFormat(chara)
End If
End If
Next item
Next paragraph
End If
Next ent
Online documentation link for Character format:
http://help.syncfusion.com/ug_71/docio/WCharacterFormat.htmlPlease let me know if you need any further assistance regarding this.
Best Regards,
Bhuvana