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. Image for the cookie policy date

Using document.Find not only to find the first result, but everything


I use this:

TextSelection textSelection = document.Find(findThis, false, false);

                    if (textSelection != null)
                    {
                        WTextRange text = textSelection.GetAsOneRange();
                        text.CharacterFormat.TextColor = Color.Red;
                        text.CharacterFormat.FontSize = 12;
                        text.CharacterFormat.UnderlineStyle = UnderlineStyle.Thick;

                    }

5 Replies

TE Testname April 21, 2016 07:24 AM UTC

If I use document.Replace(findeDas, ersetzeDasProduktiv, false, false) he will replace everthing, but using TextSelection textSelection = document.Find(findThis, false, false); he will only find just one


VR Vijay Ramachandran Syncfusion Team April 22, 2016 11:08 AM UTC

Hi,

Thank you for contacting Syncfusion support.

On further analysis with given details, we suspect you are trying to find all the words in a Word document using WordDocument.Find method. As per the behaviour of WordDocument.Find API, it will finds only the first occurrence in the document. If you want to find all the matching word in a document, you can use
WordDocument.FindAll API, it will help you to find all the occurrence in the Word document.

Also you are using the WordDocument.Replace API to replace the text in Word document. As per the behaviour of this API, it will replace all the matches in Word document. If your requirement is only replacing first occurrence means you could make
WordDocument.ReplaceFirst property as True before you using the WordDocument.Replace API, it will replace only the first occurrence in the Word document.

Please refer the following UG documentation link to know more about the Find and Replace functionality of DocIO.

http://help.syncfusion.com/file-formats/docio/working-with-find-and-replace

If we misunderstood any of your requirement then kindly elaborate the actual requirement with detailed description. Thereby we will analyse further on the mentioned case and will provided you appropriate solution.

Regards,
Vijay R



TE Testname April 22, 2016 11:51 AM UTC

I used GetAsOneRange(); before to format a specific match, what should I use instead ?

My Code:

      WTextRange text = textSelections.GetAsOneRange();//GetAsOneRange()
                        text.CharacterFormat.TextColor = Color.Red;
                        text.CharacterFormat.FontSize = 12;
                        text.CharacterFormat.UnderlineStyle = UnderlineStyle.Thick;


TE Testname April 22, 2016 11:53 AM UTC

forget it I found the soulution


VR Vijay Ramachandran Syncfusion Team April 25, 2016 07:27 AM UTC

Hi,

Thank you for your update.

Let us know if you have any other clarification.

Regards,
Vijay R


Loader.
Live Chat Icon For mobile
Up arrow icon