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

Free Support Forum - aspose.com

Can't remove the first of a table

Hi, I am getting this error when I use row.remove() on the first row in a table.

java.lang.IllegalStateException: Cannot remove because there is no parent.
at com.aspose.words.Node.remove(Unknown Source) ~[aspose-words-19.4.jar:19.4]
at com.manulife.pension.pinpointpricingclient.vo.DeleteNullRows.nodeInserted(DeleteNullRows.java:29) ~[classes/:na]

DeleteNullRows is below:

public class DeleteNullRows implements INodeChangingCallback {
public void nodeInserted(NodeChangingArgs arg0) throws Exception {
Node node = arg0.getNode();

if (node.getNodeType() == NodeType.RUN) {
Run run = (Run) node;
if (run.getRange().getText().contains(“DELETE”)) {
Row row = (Row) run.getAncestor(NodeType.ROW);
if (row != null) {
log.info("Row info:: " + row.getCells().toArray()[0].getText());


I think, inside INodeChangingCallback, you can insert a bookmark at the place whose row you want to delete. And later when table is fully constructed (after builder.endTable), you can find the ancestor row of BookmarkStart and remove it. Hope, this helps.

1 Like