Free Support Forum - aspose.com

Cloning Rows

Hi,

What I'm trying to do is copy rows 19 - 30 as a group and paste it at a certain point depending on the criteria. Here is my code below...the code clones/copies 19 - 30 but it doesn't clone it and paste it as a group. When the template comes out it looks like this:

19
19
20
20
21
21...etc.

I want it to look like this:
19
20
21
19
20
21
19
20
21

Any help is muchly appreciated. Thanks!


Dim myTable2 As Aspose.Words.Tables.Table = doc.Sections(0).Body.Tables(0)

'Get row of table

Dim myRow19 As Aspose.Words.Tables.Row = myTable2.Rows(19)

Dim myRow20 As Aspose.Words.Tables.Row = myTable2.Rows(20)

Dim myRow21 As Aspose.Words.Tables.Row = myTable2.Rows(21)

Dim myRow22 As Aspose.Words.Tables.Row = myTable2.Rows(22)

Dim myRow23 As Aspose.Words.Tables.Row = myTable2.Rows(23)

Dim myRow24 As Aspose.Words.Tables.Row = myTable2.Rows(24)

Dim myRow25 As Aspose.Words.Tables.Row = myTable2.Rows(25)

Dim myRow26 As Aspose.Words.Tables.Row = myTable2.Rows(26)

Dim myRow27 As Aspose.Words.Tables.Row = myTable2.Rows(27)

Dim myRow28 As Aspose.Words.Tables.Row = myTable2.Rows(28)

Dim myRow29 As Aspose.Words.Tables.Row = myTable2.Rows(29)

Dim myRow30 As Aspose.Words.Tables.Row = myTable2.Rows(30)

Dim refRow19 As Aspose.Words.Tables.Row = myRow19

Dim refRow20 As Aspose.Words.Tables.Row = myRow20

Dim refRow21 As Aspose.Words.Tables.Row = myRow21

Dim refRow22 As Aspose.Words.Tables.Row = myRow22

Dim refRow23 As Aspose.Words.Tables.Row = myRow23

Dim refRow24 As Aspose.Words.Tables.Row = myRow24

Dim refRow25 As Aspose.Words.Tables.Row = myRow25

Dim refRow26 As Aspose.Words.Tables.Row = myRow26

Dim refRow27 As Aspose.Words.Tables.Row = myRow27

Dim refRow28 As Aspose.Words.Tables.Row = myRow28

Dim refRow29 As Aspose.Words.Tables.Row = myRow29

Dim refRow30 As Aspose.Words.Tables.Row = myRow30

'Clone row

Dim newRow19 As Aspose.Words.Tables.Row = CType(myRow19.Clone(True), Aspose.Words.Tables.Row)

Dim newRow20 As Aspose.Words.Tables.Row = CType(myRow20.Clone(True), Aspose.Words.Tables.Row)

Dim newRow21 As Aspose.Words.Tables.Row = CType(myRow21.Clone(True), Aspose.Words.Tables.Row)

Dim newRow22 As Aspose.Words.Tables.Row = CType(myRow22.Clone(True), Aspose.Words.Tables.Row)

Dim newRow23 As Aspose.Words.Tables.Row = CType(myRow23.Clone(True), Aspose.Words.Tables.Row)

Dim newRow24 As Aspose.Words.Tables.Row = CType(myRow24.Clone(True), Aspose.Words.Tables.Row)

Dim newRow25 As Aspose.Words.Tables.Row = CType(myRow25.Clone(True), Aspose.Words.Tables.Row)

Dim newRow26 As Aspose.Words.Tables.Row = CType(myRow26.Clone(True), Aspose.Words.Tables.Row)

Dim newRow27 As Aspose.Words.Tables.Row = CType(myRow27.Clone(True), Aspose.Words.Tables.Row)

Dim newRow28 As Aspose.Words.Tables.Row = CType(myRow28.Clone(True), Aspose.Words.Tables.Row)

Dim newRow29 As Aspose.Words.Tables.Row = CType(myRow29.Clone(True), Aspose.Words.Tables.Row)

Dim newRow30 As Aspose.Words.Tables.Row = CType(myRow30.Clone(True), Aspose.Words.Tables.Row)

'Insert created row into the table

myTable2.InsertAfter(newRow19, refRow19)

myTable2.InsertAfter(newRow20, refRow20)

myTable2.InsertAfter(newRow21, refRow21)

myTable2.InsertAfter(newRow22, refRow22)

myTable2.InsertAfter(newRow23, refRow23)

myTable2.InsertAfter(newRow24, refRow24)

myTable2.InsertAfter(newRow25, refRow25)

myTable2.InsertAfter(newRow26, refRow26)

myTable2.InsertAfter(newRow27, refRow27)

myTable2.InsertAfter(newRow28, refRow28)

myTable2.InsertAfter(newRow29, refRow29)

myTable2.InsertAfter(newRow30, refRow30)

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I think that you should use the following code:

Dim originalRows As ArrayList = New ArrayList()

'Write rows collection into the ArrayList

For i As Integer = 19 To 30

originalRows.Add(myTable2.Rows(i))

Next

'Declare first ref row

'it should be the last row in the collection.

Dim refRow As Row = myTable2.Rows(30)

'Clone and insert rows after ref row

For Each row As Row In originalRows

'Clone current row

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

'Inser clone of row after ref row

myTable2.InsertAfter(clone, refRow)

'The next row should be inserted after newly inserted row

refRow = clone

Next

Hope this helps.

Best regards.