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

Free Support Forum - aspose.com

Move Cursor above the table

Hi Team,

I am trying to move the cursor to above the table. My functionality is to remove a table and replace it with a mergefield where the table was present. But I tried the below code and I am getting Null pointer Exception because of no Previous Sibling

builder.insertField(“MERGEFIELD " + mergeField + " \* MERGEFORMAT”);

Please help me in doing this funtionality.



Thanks for your query.

Please share your sample file and console application(runnable) with us for our testing. Provide any image which shows your exact requirement for our better understanding. We will reproduce the problem and provide our feedback after analysis.

Hi Team,

I am trying to remove a table and replace a Mergefield there at the sama position where the table was present.

Here is the below sample code,

String filePathSDT = "C:\\Users\\wb541348\\Project\\TestDoc.docx";
		InputStream instreamSDT =new FileInputStream(filePathSDT);
		Document doc = new Document(filePathSDT);
		DocumentBuilder builder = new DocumentBuilder(doc);
		NodeCollection<Table> tablenodes = doc.getChildNodes(NodeType.TABLE, true);
		for(Table table : tablenodes) {
			builder.insertField("MERGEFIELD " + "Test" + " \\* MERGEFORMAT");

Above code executes properly at times , and it fails at times with Null pointer exception at builder.moveTo(table.getPreviousSibling());

Please let me know how to handle them, What if I dint have a previous sibling and How should I remove the table and replace a MergeField there in those cases.

Prasanna Shanmuganathan


Please follow your other thread for further proceedings.