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

Insert a list at a specified position

4 Answers 105 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Iron
Veteran
Dan asked on 16 Nov 2017, 06:56 AM

Hi,

I have a template that is a Word 2003 format. I have converted the template to docx and inserted some bookmarks in order to have the possibility to use document processing to insert text in the template. The template is provided as is so I can not change that.

I have managed to insert text successfully at the position of the bookmark, but I can not make the list work.

Here is the code I have

private void insertListAt(string bookmarkName, IEnumerable<string> values)
{
    if(values == null || !values.Any())
    {
        return;
    }
    var bookmark = document.EnumerateChildrenOfType<BookmarkRangeStart>().FirstOrDefault(rangeStart => rangeStart.Bookmark.Name == bookmarkName);
    if (bookmark != null)
    {
        editor.MoveToParagraphStart(bookmark.Paragraph);
        foreach(string value in values)
        {
            var line = editor.InsertLine(value);
            line.Paragraph.ListId = list.Id;
            line.Paragraph.ListLevel = 4;
        }
    }
}

but this code does not work.

The values are placed one after the other with no new line between them and the list is not applied to the items

4 Answers, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
Iron
Veteran
answered on 16 Nov 2017, 08:55 AM

Hi,

It seems today that its working. Sorry about this.

0
Lee
Top achievements
Rank 1
answered on 20 Jun 2018, 12:53 AM
How did you manage to insert text successfully at the position of the bookmark. Can you post an example?
0
Dan
Top achievements
Rank 1
Iron
Veteran
answered on 20 Jun 2018, 05:38 AM

Hi Lee,

Unfortunally I don't have the code anymore because this product did not satisfy all the requirements that I needed.

But if you replace the foreach statement with an editor.InsertText(text) you should get the expected result.

0
Tanya
Telerik team
answered on 22 Jun 2018, 12:48 PM
Hello,

You can move the position of the RadFlowDocumentEditor instance to the start of the inline and then, as Dan suggested, you can insert the content using the InsertText() method.
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
editor.MoveToInlineStart(bookmarkStart);
editor.InsertText("Before the bookmark");

In case you need to find all the bookmarks in the document, you could take advantage of the EnumerateChildrenOfType() method:
var allBookmarkStarts = document.EnumerateChildrenOfType<BookmarkRangeStart>();

Hope this is helpful.

Regards,
Tanya
Progress Telerik

Tags
WordsProcessing
Asked by
Dan
Top achievements
Rank 1
Iron
Veteran
Answers by
Dan
Top achievements
Rank 1
Iron
Veteran
Lee
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or