Inserting Row into exitsting table

Hi,
I am using Aspose.Words 6.1.0 for .NET with Temporary licence. I am reading a document template, that template having a table with one row.
now i need to create another row to the same table, how can i add new row to existing table or how can i copy the first row data and placed as a second row??
I used the code like,

Document docQualItem = new Document(oQualItemTemplate);
DocumentBuilder builderMainSec= new DocumentBuilder(docQualItem );
builderMainSec.MoveToSection(-1);
builderMainSec.MoveToCell(0, 1, 0, 0); // template have one table and only one row
Row newRow = new Row(docQualItem );
builderMainSec.InsertNode(newRow); // i am getting error here...

Thanks & Regards,
Srinu Dhulipalla

Hi
Thanks for your inquiry. You can clone first row and insert cloned row into the table. See the following code:

Row refRow = tab.LastRow;
// Add 5 rows
for (int i = 0; i < 5; i++)
{
    // Clone row
    Row clone = refRow.Clone(true);
    // Remove content from the row
    clone.GetChildNodes(NodeType.Paragraph, True).Clear();
    foreach (Cell cell in clone.Cells)
    {
        cell.EnsureMinimum();
    }
    // insert row
    tab.Rows.Add(clone);
}

Hope this helps.
Best regards.

Hi Alexey,
Thanks for your explanation…
but i am not able to give the reference Row to existing table… like

Row refRow = tab.LastRow;

Bcoz, table is already there in the template(i am not created table in template), so only i can able to move to perticular row in table like,

builderMainSec.MoveToCell(0, 1, 0, 0);

from there i need to create 2nd row…
after moving builder to 1st row of table, how can i create 2nd row…
If i created the table, then i can able to follow the same logic above you explained, but the table is alreday there in template with one row… how should i refer to table like, tab.LastRow;

Hi
You can use the following code :

// Get table
Table tab = doc.FirstSection.Body.Tables[0];
// Get last row
Row refRow = tab.LastRow;

Hope this helps.
Best regards,

Hi Alexey,
Thanks for you help…!
It’s working fine now as you said abov… thanks for your explanation.
Regards,
Srinu Dhulipalla

There is no clone function in Java. I tried this but no luck

Table tab = doc.getFirstSection().getBody().getTables().get(0);
Row refRow = tab.getLastRow();
Row clone = new Row(doc);

tab.getRows().add(clone);

Hi

Thanks for your request. In Java you should use deepClone method. See the following link:
https://reference.aspose.com/words/net/aspose.words/node/clone/
Best regards.