How to get a bookmark located in a cell ?
Hello,
Attachment: testTab_7ab314.zip
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
SIGN IN To post a reply.
7 Replies
DB
Dilli Babu Nandha Gopal
Syncfusion Team
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.
FL
Florider
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.
DB
Dilli Babu Nandha Gopal
Syncfusion Team
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.
FL
Florider
January 18, 2019 03:04 PM UTC
Thank you very much for your answer.
Attachment: GenerateWordTab_d721069b.zip
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
DB
Dilli Babu Nandha Gopal
Syncfusion Team
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.
FL
Florider
January 22, 2019 10:27 AM UTC
Hello ! Thanks for your help, it works very well !
Flo
DB
Dilli Babu Nandha Gopal
Syncfusion Team
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..
SIGN IN To post a reply.
- 7 Replies
- 2 Participants
-
FL Florider
- Jan 16, 2019 10:48 AM UTC
- Jan 22, 2019 10:47 AM UTC