C# Word Library
C# Word - Table Processing in C#.NET
Provide C# Users with Variety of Methods to Setup and Modify Table in Word Document
With C#.NET Word document table processing Interface control (XDoc.Word). Users can also process table in Word document.
Create Table in Word
The following demo code will show you how to create a table in body only. You can create table in other story as the same way.
String docFilePath = @"";
//Open the document
DOCXDocument document =DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a table with 3 columns and 3 rows for document
ITable table = doc.CreateTable();
//Save the document
doc.Save(@"");
Properties Setup in Table
In C# class programming, you can use specific APIs to process table in Word document, such as setting and modifying properties in table.
String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main ducument
IDocument doc = document.GetDocument();
//Document clone
IDocument doc0 = doc.Clone();
//Create a tablefor document
ITable table = doc0.CreateTable(3,3);
//Table properties
//Cell margin
table.SetCellTopMargin(200);
//Table indent
table.SetTblIndent(500);
//Table alignment
table.SetTableAlignment(TableAlignment.Right);
//Shadow
table.SetShadowFillColor(false, Color.Red);
//Save the document
doc0.Save(@"");
Create, Add and Delete Table Row in Word
A table must contains one row at least, if you want to create a new row or delete an existing one, you can use our APIs in class ITable, and the following demo code show you finish this work.
String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main ducument
IDocument doc = document.GetDocument();
//Document clone
IDocument doc0 = doc.Clone();
//Create a tablefor document
ITable table = doc0.CreateTable(3, 3);
//Create a row with 3 cells for table
ITableRow row = table.CreateRow(3);
//Save the document
doc0.Save(@"");