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)
<span style="color:blue;">Dim</span> para <span style="color:blue;">As</span> <span style="color:#2b91af;">Paragraph</span>
<span style="color:green;">' We will be inserting into the parent of the destination paragraph.</span>
<span style="color:blue;">Dim</span> dstStory <span style="color:blue;">As</span> <span style="color:#2b91af;">CompositeNode</span> = insertAfterNode.ParentNode
<span style="color:green;">' This object will be translating styles and lists during the import.</span>
<span style="color:blue;">Dim</span> importer <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">NodeImporter</span>(srcDoc, insertAfterNode.Document, <span style="color:#2b91af;">ImportFormatMode</span>.KeepSourceFormatting)
<span style="color:blue;">Dim</span> isFirstPara <span style="color:blue;">As</span> <span style="color:blue;">Boolean</span> = <span style="color:blue;">True</span>
<span style="color:green;">' Loop through all sections in the source document.</span>
<span style="color:blue;">For</span> <span style="color:blue;">Each</span> srcSection <span style="color:blue;">As</span> <span style="color:#2b91af;">Section</span> <span style="color:blue;">In</span> srcDoc.Sections
<span style="color:green;">' Loop through all block level nodes (paragraphs and tables) in the body of the section.</span>
<span style="color:blue;">For</span> <span style="color:blue;">Each</span> srcNode <span style="color:blue;">As</span> <span style="color:#2b91af;">Node</span> <span style="color:blue;">In</span> srcSection.Body
<span style="color:green;">' Let's skip the node if it is a last empty paragraph in a section.</span>
<span style="color:blue;">If</span> srcNode.NodeType.Equals(<span style="color:#2b91af;">NodeType</span>.Paragraph) <span style="color:blue;">Then</span>
para = <span style="color:blue;">CType</span>(srcNode, <span style="color:#2b91af;">Paragraph</span>)
<span style="color:blue;">If</span> insertAfterNode.NodeType = <span style="color:#2b91af;">NodeType</span>.Table <span style="color:blue;">Then</span>
<span style="color:green;">' :to do</span>
<span style="color:blue;">ElseIf</span> insertAfterNode.NodeType = <span style="color:#2b91af;">NodeType</span>.Paragraph <span style="color:blue;">Then</span>
<span style="color:blue;">If</span> <span style="color:blue;">DirectCast</span>(insertAfterNode, <span style="color:#2b91af;">Paragraph</span>).IsEndOfSection <span style="color:blue;">AndAlso</span> (<span style="color:blue;">Not</span> para.HasChildNodes) <span style="color:blue;">Then</span>
isFirstPara = <span style="color:blue;">False</span>
<span style="color:blue;">Continue For</span>
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:green;">' This creates a clone of the node, suitable for insertion into the destination document.</span>
<span style="color:blue;">Dim</span> newNode <span style="color:blue;">As</span> <span style="color:#2b91af;">Node</span> = importer.ImportNode(srcNode, <span style="color:blue;">True</span>)
<span style="color:green;">' Insert new node after the reference node.</span>
dstStory.InsertAfter(newNode, insertAfterNode)
insertAfterNode = newNode
<span style="color:blue;">Next</span> srcNode
<span style="color:blue;">Next</span> srcSection
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
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