We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to duplicate table rows and keep their formatting


I have to programatically add rows to an user-defined word template. I would like to do with Aspose.Words the same exact operation as in Word: select row, copy, paste. This inserts a row with the same border styles and fonts.

I've tried using the Clone and InsertAfter methods, with no luck (cannot InsertAfter).

Dim DuplicatedRow As Node = DocBuild.CurrentStory.Tables(TableIdx).Rows(RowIdx).Clone(True)

DocBuild.CurrentStory.Tables(TableIdx).Rows(RowIdx).InsertAfter( DuplicatedRow , _

Can you show me how to accomplish that, or point me to the relevant API ?



Thanks for your inquiry. I think you should use the following code to achieve this.

Dim newRow As Row = CType(doc.FirstSection.Body.Tables(0).Rows(index).Clone(True), Row)

doc.FirstSection.Body.Tables(0).InsertAfter(newRow, doc.FirstSection.Body.Tables(0).Rows(index))

Or use the following code.

Dim index As Integer = 2

Dim newRow As Row = CType(doc.FirstSection.Body.Tables(0).Rows(index).Clone(True), Row)

doc.FirstSection.Body.Tables(0).Rows.Insert(index + 1, newRow)

I hope that it will help you.

Best regards.

Hello Alexey,

It works perfectly. I had missed how Insert methods works.