Append new row to an existing table


#1

I have a table that has a header defined in Word and one row that is blank. I have a bookmark marking the first cell in the table so I can jump straight to it. The table has 2 rows and 7 columns.

I test for the row being the last row and if so I want to insert another row to take more data at the end of the table rows.

if (row.IsLastRow)

{

Row rr = new Row(doc);

rr.EnsureMinimum();

for (int iCnt=1;iCnt <= 6;iCnt++)

{

Cell cl = new Cell(doc);

cl.EnsureMinimum();

rr.Cells.Add(cl);

}

table.Rows.Add(rr);

This all works BUT the added rows do not appear in Word when the document is opened. The last rows do not show any cells or text so I beleive that the document is not well formed. What am I doing wrong?

Thanks


#2

The cells you are inserting have zero width by default and therefore could not be seen.

The following code will work much better in your case:

if (row.IsLastRow)

{

Row rr = (Row)row.Clone(true);

row.ParentTable.Rows.Add(rr);

}

Best regards,


#3

Thanks!!!

That did the job beautifully!

And thanks for the prompt reply - now I can deliver this to my client tomorrow!!!