CellCollectionToArray Method |
Namespace: Aspose.Words.Tables
Document doc = new Document(MyDir + "Tables.docx"); // 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) TableCollection tables = doc.FirstSection.Body.Tables; // We can make a new array to clone all of the tables in the collection Assert.AreEqual(2, tables.ToArray().Length); // Iterate through all tables in the document for (int i = 0; i < tables.Count; i++) { // Get the index of the table node as contained in the parent node of the table Console.WriteLine($"Start of Table {i}"); RowCollection rows = tables[i].Rows; // RowCollections can be cloned into arrays Assert.AreEqual(rows, rows.ToArray()); Assert.AreNotSame(rows, rows.ToArray()); // Iterate through all rows in the table for (int j = 0; j < rows.Count; j++) { Console.WriteLine($"\tStart of Row {j}"); CellCollection cells = rows[j].Cells; // RowCollections can also be cloned into arrays Assert.AreEqual(cells, cells.ToArray()); Assert.AreNotSame(cells, cells.ToArray()); // Iterate through all cells in the row for (int k = 0; k < cells.Count; k++) { // Get the plain text content of this cell string cellText = cells[k].ToString(SaveFormat.Text).Trim(); // Print the content of the cell Console.WriteLine($"\t\tContents of Cell:{k} = \"{cellText}\""); } Console.WriteLine($"\tEnd of Row {j}"); } Console.WriteLine($"End of Table {i}\n"); }