We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Reading Data From a Table

I have a word document that has multiple tables.

How can I access the last table in the document?

How can I read data inside the rows based on the table header?. for example the table will look like this:

ID Name Comment

0001 Abel comment to read.

I need to be able to read the data inside each cell..

Please Advice and Thank You for you time

Hi,


Thanks for your inquiry and sorry for the delayed response.
:
How can I access the last table in the document?
You can access the last table in your Word document by using the following code:
NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);
int count = tables.getCount();
Table lastTable = (Table)tables.get(count - 1);
:
How can I read data inside the rows based on the table header?
You can just loop through all rows and get value of each cell in the row. For example see the following code:
for (Row row : lastTable.getRows()) {
for (Cell cell : row.getCells()) {
System.out.println(cell.toTxt().trim());
}
}
}
Moreover, I would suggest you please read the following article to learn how to work with Word columns in Aspose.Words:
http://docs.aspose.com/display/wordsjava/working+with+columns

I hope, this will help.

Best Regards,