Aspose.Words

Extracting Plain Text from a Table

A Table like any other node in Aspose.Words has access to a Range object. Using this object, you can call methods over the entire table range to extract the table as plain text. The Range.Text property is used for this purpose.

Example PrintTableRange

Shows how to print the text range of a table.

[Java]

 

Document doc = new Document(getMyDir() + "Table.SimpleTable.doc");

 

// Get the first table in the document.

Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);

 

// The range text will include control characters such as "\a" for a cell.

// You can call ToString and pass SaveFormat.Text on the desired node to find the plain text content.

 

// Print the plain text range of the table to the screen.

System.out.println("Contents of the table: ");

System.out.println(table.getRange().getText());

 

 

The same technique is used to extract the content from individual cells of a table only.

Example PrintRowAndCellRange

Shows how to print the text range of row and table elements.

[Java]

 

// Print the contents of the first row to the screen.

System.out.println("\nContents of the row: ");

System.out.println(table.getFirstRow().getRange().getText());

 

// Print the contents of the last cell in the table to the screen.

System.out.println("\nContents of the cell: ");

System.out.println(table.getLastRow().getLastCell().getRange().getText());