XDoc.Word
Features
Tech Specs
How-to C#
Pricing

C# Word Library
C# Word - Table Row Processing in C#.NET


How to Set and Modify Table Rows in Word Document with C#.NET Solutions





C#.NET Word document table row processing Interface control (XDoc.Word). It can be used to process table rows in an existing or new Word file.


Create and Add Rows in Table



The following C# demo code will show how to create a new row in current table

String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a table in body
ITable table = doc.CreateTable(3, 3);
//Create a table row for table
ITable row = table.CreateRow(3);
//Save the document
doc.Save(@"");


Set Properties of Table Row



In C# class programming, you can use specific APIs to process table row in Word document. You can set properties of all row in table, and modify them.

String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a Table for document
ITable table = doc.CreateTable(3, 3);
//Get all rows in table
List<ITableRow> rows = table.GetRows();
//Get first row
ITableRow row = rows[0];
//Set properties for table row
//CantSplit
row.SetCanSplit(true);
//Row height
row.SetRowHeight(1000);
//Table row repeat on every new page
row.SetTblHeader(true);
//MORE TODO:
//
//
doc.Save(@"");


Create, Add and Delete Cells in Table



If you want to create or add new cells and delete existing cells in table row, you can use our APIs in class ITableRow. The following demo code describe how to create new cells in table row.

String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a Table for document
ITable table = doc.CreateTable(3, 3);
//Get all rows in table
List<ITableRow> rows = table.GetRows();
//Get first row
ITableRow row = rows[0];
//Create a new cell for row
ITableCell cell = row.CreateCell();
//MORE TODO:
//
//
doc.Save(@"");