Multiple table insertions merge into one table

I’m using the excel2word code that you created awhile back to import some excel ranges into a word document. The import worked great until I found I had to process several spreads and import them, then the tables all merge together.
Simple explanation: I create spread1, grab range1, move to bookmark1
write line the company name and then insert the spread range table.
Grab bookmark2, move to bookmark 2 and insert range.
Next create spread 2 and repeat the above steps
Instead of getting
Company1
Table1
Company2
Table2

I end up with
Company1
Company2
Table1
Table 2
with the tables merged into a single table. They need to be unique tables with spacing and descriptive information between them.
Here is a code sample, the undeclared variables are passed into the function.
The application is VB.Net
Thanks
Donna

Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.MoveToBookmark(bookmark, False, False)
Dim sectionIndex As Integer = doc.Sections.IndexOf(builder.CurrentSection)
'Get array of Word tables, every table in this array represents a part of Excel worksheet.
Dim partsArray As ArrayList = GetRangePartsArray(rangename, worksheet, doc, sectionIndex)
'Insert all tables into the Word document
builder.MoveToBookmark(bookmark, False, False)
builder.Writeln(String.Empty)
builder.Writeln("Company name")
For Each table As Table In partsArray
'Insert table
builder.CurrentSection.Body.AppendChild(table)
Exit For
Next

Hi
Thanks for your request. The problem occurs because you append tables to the end of current section. But you should insert tables directly after bookmark. Please try using the following code:

builder.MoveToBookmark(Bookmark, False, False)
builder.Writeln(String.Empty)
builder.Writeln("Company name")
Dim refNode As Node = builder.CurrentParagraph
For Each table As Table In partsArray
'Insert table
refNode.ParentNode.InsertAfter(table, refNode)
refNode = table
Next

Hope this helps.
Best regards.

I’m still getting the same thing. I think I probably didn’t explain it quite as well as I should have.
the code I put up there is being run form a loop.
for example
Process Spread1. Send spread and document to the above function and add spread ranges to the document.
This document is returned, the next spread is generated and again sent to the above function with the prevously modified document. This continues until all the spreadranges that the user selected are added to the document. I suspect it has something to do with it always going to the same place on the bookmark, but I would have thought that regardless of whether it went to the top or the end of the section the text and table would remain intact and the new data would be below or above it. For some reason the code thinks that it should be appending to the existing table it find at the bookmark, even though there should be text separating the two tables. I even tried putting a begin table and end table before the table insertion code, hoping it would separate it that way, but it still manages to append to the table. Is there an embeded name property in the table that it is using which is causing it to associate itself to the existing table?
Donna

Hi
Thanks for your explanation. Could you please create sample application that will allow me to reproduce this issue? Also please attach your output document and the document that will show me how the output should looks like.
Best regards.

The original code is in a website, so I moved it into a winforms app and cut out alot of the extraneous stuff and hard coded in the information that was pulled form database. Messy, but should give you an idea of what is happening. I also included the generated document and highlighted in red the tables that are causing the problems. Also, is there a way to associate my username with my companies license? Or does that matter.

Hi
Thank you for additional information. Please try using the following code:

builder.MoveToBookmark(bookmark, False, True)
builder.Writeln(String.Empty)
builder.Writeln("Company name")
Dim refNode As Node = builder.CurrentParagraph
For Each table As Table In partsArray
'Insert table
refNode.ParentNode.InsertAfter(table, refNode)
refNode = table
Next

Hope this helps.
Best regards.

Perfect!! Exactly what I needed.
Thanks
Donna