# Row

Use DsWord to add a new row, delete an existing row, format a row, and fetch the row index in a table. Learn more in DsWord docs.

## Content

DsWord provides the [Row](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Row.html) class representing a table row element. A row can be added to a table through [Add](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RowCollection.Add.html) method of the [RowCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RowCollection.html) class. DsWord provides you the access to the formatting properties of table row using [Format](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Row.Format.html) property of the **Row** class along with the [RowFormat](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RowFormat.html) class properties. In addition to formatting a row, DsWord allows you to get the row index, which can be done using [Index](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Row.Index.html) property of the **[Row](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Row.html)**[ class.](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Row.html)

## Add Row

To add a new row to a table:

1. Access the table from the table collection using [Tables](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.Tables.html) property of the **RangeBase** class.
2. Add a row to the table using **Add** method of the **RowCollection** class.

```csharp
//Load the document and access the table
doc.Load("CreateTable.docx");
Table t=doc.Body.Sections.First.GetRange().Tables[0];

//Add a new row
string[] newrow = new string[4] { "NR1", "NR2", "NR3", "NR4" };  
t.Rows.Add(newrow);

//Save the document
doc.Save("RowAdded.docx");
```

## Delete Row

To delete a row from a table:

1. Access the table from the table collection using **Tables** property of the **RangeBase** class.
2. Delete a row of the table using the [Delete](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.Delete.html) method.

```csharp
//Load the document and access the table
doc.Load("CreateTable.docx");
Table t = doc.Body.Sections.First.GetRange().Tables[0];

//Delete the fourth row from the table
t.Rows[3].Delete();
            
//Save the document
doc.Save("RowDeleted.docx");
```

## Get Row Index

To fetch the row index from a table:

1. Access the table from the table collection using **Tables** property of the **RangeBase** class.
2. Get the row index of third row in the table using the **Index** property.
3. Display the row index on the console.

```csharp
//Load the document and access the table
doc.Load("CreateTable.docx");
Table t = doc.Body.Sections.First.GetRange().Tables[0];

//Get the row index
int i=t.Rows[2].Index;

//write the row index on the console
Console.WriteLine("Row Index for selected row is:" + i);
```

## Format Rows

To format the rows in a table:

1. Access the table from the table collection using **Tables** property of the **RangeBase** class.
2. Set alignment for the table row using [Alignment](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RowFormat.Alignment.html) property of the **RowFormat** class.
3. Set spacing between the cells using [Spacing](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RowFormat.Spacing.html) property of the **RowFormat** class.

```csharp
//Load the document and access the table
doc.Load("CreateTable.docx");
Table t = doc.Body.Sections.First.GetRange().Tables[0];

//Set the alignment of a row and spacing between the cells
t.Rows[0].Format.Alignment = TableAlignment.Right;
t.Rows[0].Format.Spacing = 4F;

//Save the document
doc.Save("FormattedRow.docx");
```

For more information about implementation of rows using DsWord, see [DsWord sample browser](https://developer.mescius.com/documents-api-word/demos/).