Inserting Rows In Table

#1) In this code, is this being done efficiently? Should I go to 3 ParentNodes to locate the table to get the table row count?

builder.MoveToMergeField("mytable")
If builder.CurrentParagraph.ParentNode.ParentNode.ParentNode.NodeType = Aspose.Words.NodeType.Table Then
Dim table1 As Aspose.Words.Table
table1=builder.CurrentParagraph.ParentNode.ParentNode.ParentNode
MsgBox(table1.Rows.Count)
End If

#2) Next, I wish to add rows to a table, up to an exact amount. If I have a Word table that has 4 rows, I wish to insert the correct number of rows so it has 10. If it has 3 rows, I wish to insert 7 rows, etc… I believe the above code gets me the row count, but how do I then insert rows onto the table. By the way, I just want the rows to take on the properties of the rows already in the table, so I don’t have to set height, width, etc…
Please let me know answers to #1 and #2.
Thank You,
Derek

Hi
Thanks for your request.
#1) Yes, unfortunately, you should get ParentNode 3 times to locate the table
#2) here is code that will solve this task.

'move to merge field
builder.MoveToMergeField("mytable")
If builder.CurrentParagraph.ParentNode.ParentNode.ParentNode.NodeType = Aspose.Words.NodeType.Table Then
Dim table1 As Aspose.Words.Table
table1 = builder.CurrentParagraph.ParentNode.ParentNode.ParentNode
While table1.Rows.Count < 10
'Add new row to table if rowCount<10
table1.Rows.Add(table1.LastRow.Clone(True))
End While
MsgBox(table1.Rows.Count)
End If
doc.Save("out1_97825.doc")

I hope that it will help you.
Best regards.