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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get a bookmark located in a cell ?

Thread ID:

Created:

Updated:

Platform:

Replies:

142042 Jan 16,2019 10:48 AM UTC Jan 22,2019 10:47 AM UTC WinForms 7
loading
Tags: DocIO
Florider
Asked On January 16, 2019 10:48 AM UTC

Hello,

I have a word table with a bookmark located in each cell of the first row. Each header bookmark is used to find the right columns index and then, to fill the table with the right info in each cell.
But for now, i didn't find a way to get the bookmark object located in each cell (i only get a Wparagraph, which doesn't contain a bookmark).
If i start from the bookmarks (with a bookmarkNavigator), each bookmark's content is a WParagraph (not a WTableCell).
Please, could you provide me a sample ?
If necessary, i attached my test document.

Best regards,

Flo 

Attachment: testTab_7ab314.zip

Dilli Babu Nandha Gopal [Syncfusion]
Replied On January 17, 2019 11:08 AM UTC

Hi Flo, 

Greetings from Syncfusion. 

Yes, it is possible to replace the bookmark content which is inside a Table cell. The following code example illustrates how to replace a bookmark content. 

Code example: 
 WordDocument document = new WordDocument(@"testTab.docx", FormatType.Docx); 
 //Creates the bookmark navigator instance to access the bookmark 
 BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document); 
  
 //Moves the virtual cursor to the location before the end of the bookmark "Col1" 
 bookmarkNavigator.MoveToBookmark("Col1"); 
 //Replaces the bookmark content 
 bookmarkNavigator.ReplaceBookmarkContent("Column 1",true); 
 
 //Moves the virtual cursor to the location before the end of the bookmark "Col2" 
 bookmarkNavigator.MoveToBookmark("Col2"); 
 //Replaces the bookmark content 
 bookmarkNavigator.ReplaceBookmarkContent("Column 2", true); 
 
 document.Save("Sample.docx", FormatType.Docx); 
 document.Close(); 
  
To know more about replacing a bookmark content, kindly refer the following UG documentation link. 

Regards, 
Dilli babu. 


Florider
Replied On January 17, 2019 11:49 AM UTC

Thanks for your answer but that's not my need.
I need to get each bookmark entity from each cell of the first row.
I found a way to get the cell entity from a given bookmark name (using the bookmarknavigator). So i guess there's a relation between bookmarks and cells in your object model. But i don't understand why it's not possible to find the same bookmark object (located in the same cell), but starting from the cell object.


Dilli Babu Nandha Gopal [Syncfusion]
Replied On January 18, 2019 11:05 AM UTC

Hi Flo, 

Thank you for your update. 

We have prepared a sample based on your requirement i.e., iterate the table’s first row cells and accessed the bookmark in it. The sample can be downloaded from the following link. 

Please let us know if you have questions. 

Regards, 
Dilli babu. 


Florider
Replied On January 18, 2019 03:04 PM UTC

Thank you very much for your answer.
You sample works very well with the provided document.
But i noticed a problem when i try to find the cells bookmarks into a specific table enclosed itself by another bookmark.
I changed a little part of your sample to show you the behavior with 2 different configurations (testTabOK.doc and testTabNOK.doc).
You will see a little difference on the bookmark used for the table selection :
- testTabOK.doc => the bookmark starts directly from the table
- testTabNOK.doc => the bookmark starts from a paragraph above the table 
The right wTable object is returned in both configuration but strangely the cells' bookmarks are correctly identified on testTabOK but not on testTabNOK.doc
And unfortunalely, i have hundred of word templates with the testTabNOK configuration ...
Any idea ?

Attachment: GenerateWordTab_d721069b.zip

Dilli Babu Nandha Gopal [Syncfusion]
Replied On January 22, 2019 09:07 AM UTC

Hi Flo, 

Thank you for your update. 

To retrieve the bookmark which is inside another bookmark content, GetContent method of BookmarksNavigator must be used. We have modified the sample accordingly to meet your requirement which is available in the following link. 

Please refer the following UG documentation link to know more about retrieving bookmarks and its contents. 

Kindly let us know if you have any questions. 
  
Regards, 
Dilli babu. 


Florider
Replied On January 22, 2019 10:27 AM UTC

Hello ! Thanks for your help, it works very well !

Flo



Dilli Babu Nandha Gopal [Syncfusion]
Replied On January 22, 2019 10:47 AM UTC

Hi Flo, 
  
We are glad to know that the reported issue has been resolved. Please let us know if you need any further assistance. 
  
Regards, 
Dilli babu.. 


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

;