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. Image for the cookie policy date

bookmark in a cell

i'am always evaluate your product,
i have a table with two rows
the first one is the header and the second in empty

the first row containt cells with specific bookmark,
i want to recupere the cellindex of specific bookmark

i use the current code but he don't find any bookmark in cell just wtextrange.

      Dim bknav As BookmarksNavigator = New BookmarksNavigator(a)
 Dim tbp As TextBodyPart = bknav.GetBookmarkContent
        Dim table As WTable = Nothing
        For Each element As IEntity In tbp.BodyItems
            If TypeOf element Is WTable Then
                table = CType(element, WTable)
                Exit For
            End If

For Each cell As WTableCell In table.Rows(0).Cells
            For Each para As WParagraph In cell.Paragraphs   ' y a que paragraph a l'interieur
                For Each element In para.ChildEntities
                    If TypeOf (element) Is BookmarkStart Then
                        bkname = TryCast(element, BookmarkStart).Name
                        currindex = cell.GetCellIndex
                        If bkname = "numLocalAC1" Then
                            indexNom = currindex
                        End If
                        If bkname = "localAC1" Then
                            indexPrenom = currindex
                        End If
                        If bkname = "numLotAC1" Then
                            indextelephone = currindex
                        End If
                    End If
// end code

in piece joint you  will find the document.

-------- ADD ------
after i use the 16.4 librairy the espion express don't give me any information.

thanks have a nice day

Attachment: exemple_93b491c5.zip

1 Reply

VR Vijay Ramachandran Syncfusion Team January 16, 2019 04:07 AM

Hi AtliDev,

Thank you for contacting Syncfusion support.

You can get the bookmark owner cell index by using BookmarkNagivator. Please find the example code snippet from below and let us know if it helps.
Dim document As WordDocument = New WordDocument("exemple.docx") 
    Dim bkmkNavigator As BookmarksNavigator = New BookmarksNavigator(document) 
    Dim cellIndex As Integer = -1 
    If bkmkNavigator.CurrentBookmark IsNot Nothing AndAlso bkmkNavigator.CurrentBookmark.BookmarkStart IsNot Nothing Then 
        Dim ownerParagraph As WParagraph = bkmkNavigator.CurrentBookmark.BookmarkStart.OwnerParagraph 
        If ownerParagraph.IsInCell Then 
            Dim ownerCell As WTableCell = TryCast(ownerParagraph.OwnerTextBody, WTableCell) 
            If ownerCell IsNot Nothing Then cellIndex = ownerCell.GetCellIndex() 
        End If 
    End If 

You can find the runnable example project from below:

Vijay R

Live Chat Icon For mobile
Up arrow icon