How to fetch the field names which are used in the aspose word template(document) from apex?
@ArunaAP Could you please attach your template here for our reference? Do you need to get merge field names or something other? Do you use Aspose.Words for Cloud or on-premises version?
Conditional Table.docx (30.2 KB)
For example, in this template I need the Account_BillingState,Account_Name,Account_BillingState field names from the template to my apex. How this field names can be fetched.
@ArunaAP Since placeholders in your template are represented as a simple text, you can use Find/Replace functionality to find them. For example see the following code:
Document doc = new Document(@"C:\Temp\in.docx");
FindReplaceOptions opt = new FindReplaceOptions();
opt.ReplacingCallback = new ReplacingCallback();
doc.Range.Replace(new Regex("<<(.+?)>>"), "", opt);
private class ReplacingCallback : IReplacingCallback
{
public ReplaceAction Replacing(ReplacingArgs args)
{
Console.WriteLine(args.Match.Groups[1].Value);
return ReplaceAction.Skip;
}
}
Could you please let us know whether you are using Cloud version of Aspose.Words? If so I will move your request into the appropriate forum and my colleagues from Cloud team will help you.