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

Free Support Forum - aspose.com

Get Table After insertHtml

If I insert an html table or multiple tables after moving to a bookmark, how would I get the table so that I could apply an additional style or formatting to it? Is there any way to get to the table by a particular id or style so that I know I’m formatting the proper table if there are multiples?




Thanks for your request. You can get any of table using an index of a table collection:

// Get collection of tables

NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);

// Get table by table index

Table myTable = (Table)tables.get(1);

Also you can try putting some bookmark inside the table and then get this table using the following code:

// Open document.

Document doc = new Document("in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

// Move DocumentBuilder cursor to the bookmark.


// Get Table, where bookmark is located.

Table myTable = (Table)builder.getCurrentParagraph().getAncestor(NodeType.TABLE);

Or you can try using getting the immediate parent of current node:


Best regards,

I can get the table inserted at the bookmark with:


I’d like to be able to get a nodeCollection of 1 or more tables that I may have inserted at the bookmark via insertHtml so that I can loop over them.

But I’m not having any luck with:

<span style=“font-size: 10pt; font-family: “Courier New”;”>documentBuilder.getCurrentParagraph().getAncestor(NodeType.TABLE)

<span style=“font-size: 10pt; font-family: “Courier New”;”>

Hi there,

Thanks for your inquiry.

Please try using the method in the code below instead. This will return an List of nodes inserted during the InsertHtml call.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>List<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”><Node> newNodes =


for(Node node : newNodes)


if(node.getNodeType() == NodeType.TABLE)



public static List<Node> InsertHtmlAndReturnNewNodes(DocumentBuilder builder, String html) throws Exception


List startingNodes = Arrays.asList(builder.getDocument().getChildNodes(NodeType.ANY, true).toArray());


List endingNodes = Arrays.asList(builder.getDocument().getChildNodes(NodeType.ANY, true).toArray());


return endingNodes;


Hopefully this helps. If you have any other queries, please feel free to ask.