public void DisplayContentOfTables()
{
//ExStart
//ExFor:Table
//ExFor:Row.Cells
//ExFor:Table.Rows
//ExFor:Cell
//ExFor:Row
//ExFor:RowCollection
//ExFor:CellCollection
//ExFor:NodeCollection.IndexOf(Node)
//ExSummary:Shows how to iterate through all tables in the document and display the content from each cell.
Document doc = new Document(MyDir + "Table.Document.doc");
// Here we get all tables from the Document node. You can do this for any other composite node
// which can contain block level nodes. For example you can retrieve tables from header or from a cell
// containing another table (nested tables).
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
// Iterate through all tables in the document
foreach (Table table in tables)
{
// Get the index of the table node as contained in the parent node of the table
int tableIndex = table.ParentNode.ChildNodes.IndexOf(table);
Console.WriteLine("Start of Table {0}", tableIndex);
// Iterate through all rows in the table
foreach (Row row in table.Rows)
{
int rowIndex = table.Rows.IndexOf(row);
Console.WriteLine("\tStart of Row {0}", rowIndex);
// Iterate through all cells in the row
foreach (Cell cell in row.Cells)
{
int cellIndex = row.Cells.IndexOf(cell);
// Get the plain text content of this cell.
string cellText = cell.ToString(SaveFormat.Text).Trim();
// Print the content of the cell.
Console.WriteLine("\t\tContents of Cell:{0} = \"{1}\"", cellIndex, cellText);
}
//Console.WriteLine();
Console.WriteLine("\tEnd of Row {0}", rowIndex);
}
Console.WriteLine("End of Table {0}", tableIndex);
Console.WriteLine();
}
//ExEnd
Assert.Greater(tables.Count, 0);
}