In this tutorial, you will learn to programmatically add rows to table in MS Word document using C#. We will first add row table Word C# at specified index in table’s row collection and later multiple empty C# Word table rows will be added to the end of table.
Steps to Add Rows to Table in MS Word Document using C#
- Install Aspose.Words for .NET package in your project via NuGet
- Import Aspose.Words and Aspose.Words.Tables namespaces
- Open MS Word Document using C# code
- Get the Table by index that you want to add Rows to
- Create a new Row class object or clone an existing Row from Table
- Add a few Cells with text Paragraphs to above Row
- Use RowCollection.Add method to add Rows to the end of Table.Rows collection
- Or use RowCollection.Insert method to insert Rows at specific index
- Resave MS Word document with added Table Rows
The following C# code of .NET console application uses Aspose Words add row to existing table in MS Word document.
Code to Add Rows to Table in MS Word Document using C#
This C# Word table add row example basically first needs to get an existing table from MS Word document using its index. But if there isn’t any table in document then you can even create table in Word using C# code. The code first C# Word table insert row at the specified index in row collection. Then it clones first table row, removes all content from all cells and finally this C# add rows to Word table code snippet will add multiple empty rows to the end of table in MS Word document.