This is a migrated thread and some comments may be shown as answers.

Iterating through Bookmarks/FormFields

3 Answers 440 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Lagrange
Top achievements
Rank 1
Lagrange asked on 21 May 2015, 03:01 PM

Hi,

I'm evaluating the Telerik.Windows.Documents API, to replace Aspose.NET in our app, for costs reason.

One of our main need, is to open existing .docx files, and replace all bookmark and formFields in the model, by business values.

I don't find any way to iterate through bookmarks and Fields. The EnumerateChildrenOfType is not usable, as Bookmark didn't inherit from DocumentElementBase.

Aspose allow it with "Document.Range.Bookmarks.Cast<Bookmark>()", can you provide an example or an equivalent ?

Regards,

Romain Lagrange

3 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 22 May 2015, 04:37 PM
Hi Lagrange,

Thank you for contacting Telerik support.

The Bookmark itself is represented as a pair of BookmarkRangeStart and BookmarkRangeEnd objects. You could obtain all the BookmarkRangeStart elements using the EnumerateChildrenOfType() method:
IEnumerable<BookmarkRangeStart> bookmarks = document.EnumerateChildrenOfType<BookmarkRangeStart>();

The next snippet is demonstrating how you could insert text in a Bookmark:
BookmarkRangeStart first = bookmarks.First();
int index = first.Paragraph.Inlines.IndexOf(first);
first.Paragraph.Inlines.Insert(index + 1, new Run(document) { Text = "In bookmark" });

For more information about Bookmarks you could refer to our documentation on the matter.

The form fields are not supported in RadWordsProcessing. We have already logged this request and you could vote and subscribe to the related public item in the feedback portal in order to receive updates about any status changes on it.

Hope this information is useful.

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Lee
Top achievements
Rank 1
Iron
answered on 20 Jun 2018, 02:02 AM
This shows how to set text for the first bookmark. How do you iterate through all the bookmarks to insert text in each one of them? 
0
Tanya
Telerik team
answered on 22 Jun 2018, 12:53 PM
Hello Lee,

Once you have obtained the bookmark start using the EnumerateChildrenOfType() method, you can traverse the collection and move the editor to the start/end of each bookmark and then insert the content using the methods of RadFlowDocumentEditor. I just sent a sample code in the other forum post with a similar question: https://www.telerik.com/forums/insert-a-list-at-a-specified-position.

Hope this helps.

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
WordsProcessing
Asked by
Lagrange
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Lee
Top achievements
Rank 1
Iron
Share this question
or