Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Sep 11, 2015 11:59 am

I am evaluating the libraries at the moment and have come across an issue, which I can't find an answer to.

I need to be able to insert a bookmark into a document at the start of a paragraph; the intended bookmark will have its start and end at the same location. It would appear that I can only append a bookmark to the current paragraph end, my problem is that I need to relocate an existing bookmark to a new location, both the old location and the new location are in this case within a table cell. I cannot replace the current cell contents, but I want to add the bookmark to the beginning of the cell.

dazfitzg
 
Posts: 5
Joined: Thu Jun 25, 2015 3:28 pm

Fri Sep 11, 2015 4:41 pm

I think I have achieved this, although it is not quite intuitive.

The steps I needed to take were,
Use a BookmarkNavigator (nav) to find the bookmark to move.
Remove the old Bookmark

Code: Select all
doc.Bookmarks.Remove(nav.CurrentBookmark);


Append the new BookmarkStart and BookMarkEnd into the 1st paragraph of the TableCell
Code: Select all
var bms = para.AppendBookmarkStart("test");
var bme = para.AppendBookmarkEnd("test");


Then move them to the start of the paragraph, in reverse order.
Code: Select all
para.Items.Insert(0,bme);
para.Items.Insert(0,bms);


This correctly inserts a bookmark as the first item in the cell.

dazfitzg
 
Posts: 5
Joined: Thu Jun 25, 2015 3:28 pm

Mon Sep 14, 2015 6:00 am

Hello,

Thanks for your sharing.
Glad to hear that you solved your issue.
Please feel free to contact us, if you have any questions or needs. We are here for help.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.Doc

cron