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

Free Support Forum - aspose.com

How to remove some specific mergefields

Hi,

we have some templates with some mergefields we want to remove and some mergefields we want to keep. Is there any other possibility to remove single mergefields than to remove the single document/xml entities describing these mergefields?


Thanks a lot!
Regards,

Jens Boeckel

Hi Jens,


Thanks for your inquiry. Please use DocumentBuilder.MoveToMergeField Method (String) method to move the cursor to a position just beyond the specified merge field and removes the merge field.

You can also determine the field type using Field.Type property and remove the field from document using Field.Remove method.

Please let us know if you have any more queries.

Hi Tahir,

thanks for the tipp. Could you give me a code example? moveToMergefield() is easy to use but afterwards I dont know how to get to the Field instance. I only find builder.getCurrentNode(), but I dont think that’s the correct way to remove the field.


Thanks a lot!
cheers

Hi Jens,


Thanks for your inquiry. Following code example shows how to move the cursor to a position just beyond the specified merge field and removes the merge field.

Document doc = new Document(MyDir + “in.docx”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToMergeField("mailmergefieldname");

doc.save(MyDir + "Out.docx");

ns1045:
but afterwards I dont know how to get to the Field instance. I only find builder.getCurrentNode(), but I dont think that's the correct way to remove the field.
Once a mail merge field is removed from the document, you cannot get that field. Could you please share some more detail about your requirement along with input and expected output Word documents? We will then provide you more information about your query along with code.