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

Free Support Forum - aspose.com

Determine if the current MailMerge field is within a region and if so- what is the region name

Hi,


Is it possible to find out if a certain field is within a region and if so what is the regions name?

Thanks,
Adam

Hi Adam,


Thanks for your inquiry. You can use FieldMergingArgsBase.TableName to get the name of the data table for the current merge operation. This property return empty string if the name is not available.

Following code example shows how to get the name of data table for current merge operation.

<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:blue;mso-font-kerning:
0pt;mso-no-proof:yes”>public<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> class EmptyRegionsHandler
: IFieldMergingCallback<o:p></o:p>

{

public void FieldMerging(FieldMergingArgs args)

{

if (args.TableName == "Suppliers")

{

// Your code

}

}

public void ImageFieldMerging(ImageFieldMergingArgs args)

{

// Do Nothing

}

}

Hi,


My objective is trying to find the region name of the region encapsulation a region, for example

<TableStart:Clients>
<> <>
<TableStart:Orders>
<> <> <>
<TableEnd:Orders>
<TableEnd:Clients>

Now in C#, i loop through all the regions individually as process them one at a time, the objective is, while processing region “Orders”, i want to get the value “Clients” because that is the encapsulating region.

Thanks,
Adam

Hi Adam,


Thanks for your inquiry. There is no direct way to get the region name that encapsulation another region as you described. However, you can achieve your requirements by using MailMerge.GetFieldNames method. This method return full merge field names including optional prefix. Does not eliminate duplicate field names.

In your case, the MailMerge.GetFieldNames method return field name as follow. Please see the attached image for detail.

TableStart:Clients
First Name
Last Name
TableStart:Orders
Order Id
Order Item Name
Order Item Description
TableEnd:Orders
TableEnd:Clients

You can find the required region name from fieldnames array. Hope this answers your query. Please let us know if you have any more queries.

Hi Tahir,


Here is the function i created to get the parent region based of a child region name. Hopefully this will help anyone else in a situation like myself.


The idea of the function is to find all the open region tags before the child tag and then get the last open tag.

Thanks,
Adam

Hi Adam,


Thanks for your feedback. We always appreciate positive feedback from our customers.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.