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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Search and replace in a bookmark

Thread ID:

Created:

Updated:

Platform:

Replies:

145596 Jun 30,2019 12:00 PM UTC Jul 2,2019 08:02 AM UTC ASP.NET Core - EJ 2 2
loading
Tags: DocIO
Pieter van Kampen
Asked On June 30, 2019 12:00 PM UTC

Hi,
I am looking for the beste way to search and replace within a bookmark. I would like to retrieve the contents of a bookmark and replace multiple words (if present). The replaced content is bookmark dependent, so I can't do a document wide find/replace.

[Your score for <scale> is <average>.]
[Your score for <scale> is <average>.]

If the above are two different bookmarks, the result could look like:
[Your score for depression is high.]
[Your score for stress is low.]

I am using bookmarks, because depending on business conditions, some bookmark text will be deleted all together.

I did not find a way to do Find and Replace in a TextBodyPart.
The only way I have found is to get the content of the bookmark as a WordDocument, then to the Find and Replace, but then I struggle to replace the contents of the bookmark with the processed WordDocument. It also does not sound as a very performant way, but I don't know that for sure.

Can you set me in the right direction?

Thanks

Pieter

Mohanaselvam  Jothi [Syncfusion]
Replied On July 1, 2019 12:28 PM UTC

Hi Pieter,

Thank you for contacting Syncfusion support.

To achieve your requirement, we suggest you get the bookmark contents and replace the text within the bookmark contents. We have prepared a sample application for the same and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/145596/ze/Sample_appplication20057606

In this sample, we have done the following things:
  1. Loads an template Word document.
  2. Get the bookmark content using BookmarksNavigator API.
  3. Iterate into bookmark contents and replace the text.
  4. Replace the bookmark content.
  5. Saves the Word document.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 


Pieter van Kampen
Replied On July 2, 2019 08:02 AM UTC

This is great! Iterating through the bookmark content is exactly what I was looking for.

Many thanks,
Pieter

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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon