How to Add New Row in an Existing Table Using Novacode DocX

6.3k views Asked by At

I have an existing table inside my Word Document which only consist headers. I want to add data on that table programmatically. I want to add rows in it but I can't find reference how to:

I tried the following:

Table myTable = document.Tables[0];
Row myRow = new Row();
myTable.Rows.Add(myRow);
myTable.Rows[0].Cells[0].Paragraphs.First().Append("Sample Data");
myTable.Rows[0].Cells[1].Paragraphs.First().Append("Sample Data");

This returns an error after building: The type 'Novacode.Row' has no constructors defined

1

There are 1 answers

1
Dzung On BEST ANSWER
Row myRow = myTable.InsertRow();
myRow.Cells[0].Paragraphs.First().Append("Sample Data");
myRow.Cells[1].Paragraphs.First().Append("Sample Data");
myTable.Rows.Add(myRow);