Same region 2 times in template but only first one is recognized

Hi,

I have a template with the same tablestart/tableend region two times.
I use ExecuteWithRegions(IMailMergeDataSource) and the first one is merged correctly however the second one remains untouched.

Do I miss something or do I have to call ExecuteWithRegions twice?

Our customers can modify there Word templates so is it possible to let it merge automatically all regions it finds, no matter how often they occur?

We are using Aspose Word Version 6.6.0.0. If we need an update let me know.

Best regards,
Torsten

P.S. I attached a sample project, could reproduce it using version 9.3.0.0

I’m using this

const string prefix = "tablestart:";

string fieldName = prefix + regionName;
var regionCount = document.MailMerge.GetFieldNames().Where(n => n.EqualsIC(fieldName)).Count();

to count the occurences of the fields and mail merge in a loop as workaround.

Let me know if there is some simpler way.

Best regards,
Torsten

Hi there,
Thanks for your request.
I believe you should look into using nested mail merge instead. This should make what you’re trying to achieve much easier. You can find the details in this article here.
Thanks

Hi,
thanks for the hint. Unfortunately we can’t use the newer version where nested mail merge support was added.

The document we want to create is some letter with a list of some items. This letter has to be in non english with an english copy. So I guess nested mail merge is also not helping very much.

I have created some helper method wich takes the merge region name and a Func wich creates the datasource inside the loop (I noticed there is no reset in IMailMergeDataSource). This is working pretty good so far.
.

Hi there,
Thanks for this additional information. If it’s applicable, it sounds like it would be easier to have the content in two different templates (one for the English copy and one for the Non-English copy), merge these two templates separately and then join them together using the Document.AppendDocument method.
Also note you can manually reset the record pointer by creating an extra method in your datasource class and calling it inside your loop. Please see below.

public void ResetRecordPointer()
{
    mRecordIndex = -1;
}

If you have any further queries, please feel free to ask.
Thanks,