Search code examples
c#novacode-docx

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


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


Solution

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