Free Support Forum - aspose.com

Clone Method Gives Unpredictable Results

This is a strange one. I am using code to add rows to a table. The table begins looking like this:

«tablestart:mytable»«Col1»

«Col2»

«Col3»«tableend:mytable»

Then I run this code:

For x = 1 to 5

Table1.rows.add(table1.lastrow.clone(true))

Next

It adds the rows, but then I want to run the ExecuteWithRegions method:

doca.MailMerge.ExecuteWithRegions(dt)

On that line of code I get the error "Found end of mail merge region 'mytable' without matching start." When I look at the document it now looks like this:

«Col1»

«Col2»

«Col3»«tableend:mytable»

«Col1»

«Col2»

«Col3»«tableend:mytable»

«Col1»

«Col2»

«Col3»«tableend:mytable»

«Col1»

«Col2»

«Col3»«tableend:mytable»

«Col1»

«Col2»

«Col3»«tableend:mytable»

«Col1»

«Col2»

«Col3»«tableend:mytable»

The ExecuteWithRegions line of code errors out, so it did not run, because the lastrow.clone method used to add rows creates this table. How do I just add rows that are blank, not having the merge fields in them?

Hi

Thanks for your request. Try to use the following code to solve this problem.

'Clone last row

Dim row As Row = CType(Table1.LastRow.Clone(True), Row)

'remove all childs of cells in the row

Dim cell As Cell = Nothing

For Each cell In row.Cells

Dim node As Node = Nothing

For Each node In cell.ChildNodes

cell.ChildNodes.Remove(node)

Next

Next

'add rows into the table

Dim i As Integer

For i = 0 To 5

Table1.Rows.Add(row.Clone(True))

Next

doc.Save("out.doc")

Best regards.