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

Free Support Forum - aspose.com

How to get coordinates of table/row/cell using Aspose Java API

I was working on get coordinates of word elements. For paragraphs and lines, I find layoutCollector and layoutEnumerator is quite powerful. I can get x,y coordinates via getRectangle() method. However, I find this method only works on span entities and I can’t get row/cell/table’s coordinates by calling this function. I go through some related questions, and I find that inserting bookmarks around the table/row/cell might be a solution. Can you provide some sample code in java to insert the bookmarks around the row or cell to get the X,Y coordinates? Or if there’re more easier ways to do that, please let me know.


You can use LayoutEnumerator.MoveParent method (LayoutEntityType) as shown below and get the position of Row and Cell.

Document doc = new Document(MyDir + "input.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

Table table = doc.getFirstSection().getBody().getTables().get(0);




We suggest you please check the code example shared here:

If you want to insert bookmark into table cell, you can use DocumentBuilder.MoveToCell method to move the cursor to the table cell and insert bookmark using DocumentBuilder.StartBookmark and DocumentBuilder.EndBookmark methods as suggested in following articles.

It’s helpful. Thank you.