We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Request WParagraph.Replace

Thread ID:

Created:

Updated:

Platform:

Replies:

79797 Feb 26,2009 06:03 AM Mar 4,2009 04:35 AM ASP.NET Web Forms (Classic) 5
loading
Tags: DocIO
Aart van Assen
Asked On February 26, 2009 06:03 AM

The Replace-method in the class WordDocument has an overload to replace a TextbodyPart.
The Replace-method in the class WParagraph doesn't have this overload.

On this moment I need this to replace a find-word by a replace-word but in another color, this in combination with a certain style.


Bhuvaneswari P [Syncfusion]
Replied On February 26, 2009 07:28 AM

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.html

Please let me know if you need any further assistance regarding this.

Best Regards,
Bhuvana



Aart van Assen
Replied On February 26, 2009 09:27 AM

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.html

Please let me know if you need any further assistance regarding this.

Best Regards,
Bhuvana





Bhuvaneswari P [Syncfusion]
Replied On March 2, 2009 08:03 AM

Hi Aart,

Thanks for the update.

Using Essential DocIO we can't access particular word or letter and format the word. We can format only each paragraph items by using the WTextRange class characterFormat property.

Unfortunately it is not possible to preserve both existing and new format while replacing. Either you can preserve the existing or new format. If you replace the format using selection(i).GetAsOneRange() method this will preserve only the new format and it will remove the old format.

Note: Sorry in the last post instead of updating find and format line which contains the find word, we have updated to find and replace the specific word.

Please let me know if you need any further clarification.

Best Regards,
Bhuvana


Aart van Assen
Replied On March 3, 2009 05:22 AM

Hello Bhuvana,
Sorry, but I don't understand the note in your last post.

Maybe it is possible to clarify what you are meaning.


Bhuvaneswari P [Syncfusion]
Replied On March 4, 2009 04:35 AM

Hi Aart,

In my first update I have updated wrongly that "If you want to find and replace the specific word" instead of updating find a word and replace the text range with formatting. So I just clarified in the last update note.

Please let me know if you need more clarification.

Best Regards,
Bhuvana



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;