Hi Tahir,
Thanks for you quick reply.
Currently, I’m using the version of Aspose.Words 14.6.0.0
This version doesn’t support the function builder.InsertDocument and I’m obliged to keep it.
The function that I’m using to insert a document at a specific bookmark is the following:
Private Sub InsertDocument(ByVal insertAfterNode As Node, ByVal srcDoc As Document)
Dim para As Paragraph
' We will be inserting into the parent of the destination paragraph.
Dim dstStory As CompositeNode = insertAfterNode.ParentNode
' This object will be translating styles and lists during the import.
Dim importer As New NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting)
Dim isFirstPara As Boolean = True
' Loop through all sections in the source document.
For Each srcSection As Section In srcDoc.Sections
' Loop through all block level nodes (paragraphs and tables) in the body of the section.
For Each srcNode As Node In srcSection.Body
' Let's skip the node if it is a last empty paragraph in a section.
If srcNode.NodeType.Equals(NodeType.Paragraph) Then
para = CType(srcNode, Paragraph)
If insertAfterNode.NodeType = NodeType.Table Then
' :to do
ElseIf insertAfterNode.NodeType = NodeType.Paragraph Then
If DirectCast(insertAfterNode, Paragraph).IsEndOfSection AndAlso (Not para.HasChildNodes) Then
isFirstPara = False
Continue For
End If
End If
End If
' This creates a clone of the node, suitable for insertion into the destination document.
Dim newNode As Node = importer.ImportNode(srcNode, True)
' Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode)
insertAfterNode = newNode
Next srcNode
Next srcSection
End Sub
After using this function, the new value of the bookmark b1 is putted after the text “text part3” (at the end of the cell) instead of putting it in the correct location (between the text “test part1” and the text “test part3”).
I think that the line code: “dstStory.InsertAfter(newNode, insertAfterNode)” is causing this behavior.
Do you have any suggestions to fix this issue?
Thanks