TableStart: / TableEnd: merge fields not working anymore

I recently upgraded from Aspose.Words.dll version 6.5.0.0 to Aspose.Words.dll version 9.1.0.0

My code works fine when compiled against 6.5.0.0, but compiled against 9.1 the exact same code no longer works.

The symptom is that when I try to merge a document that makes the use of the TableStart: and
TableEnd: Aspose mergeField keynames, the keyfields as well as the merge fields nested inside the TabelStart:/TableEnd: are not being populated or detected any more.

I would like to upgrade to the latest words version, but his is a BIG hindrance.

Hello

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words (9.2.0). I use the following code for testing:

// Create dummy datasource.
DataTable data = new DataTable("testTables()");
data.Columns.Add("TABLE1.FIELD1.firstName");
data.Columns.Add("TABLE1.FIELD2.lastName");
// Add few rows.
for (int i = 0; i <9; i++)
    data.Rows.Add(new object[]
    {
        "First Name " + i.ToString(), "Last Name " + i.ToString()
    });
Document doc = new Document(@"Test001\brokentest_Simple.docx");
doc.MailMerge.ExecuteWithRegions(data);
doc.Save(@"Test001\out.docx");

Could you please provide me a simple code which you use for fill the document with data; this will allow me to reproduce the problem on my side.
Best regards,

The issue still exists for me in 9.2.0
The code example you gave is not the path I am using to get the problem.

I am deriving a class from the IMailMergeDataSource interface and overriding the getValue method. This works fine when I have any fields outside the TableStart and TableEnd Aspose keywords (as seen earlier in my example docs)

It is very difficult for me to extract an example from my code into an external executable as my code is loaded into our framwork via CLR. I have attached code path trace that may help . One is a trace against 6.5 the other is a trace against 9.2

As stated earlier, the code works fine when compiled against 6.5 but anything later and it no longer does table merges

Hi Steven,
Thank you for posting your logs, but unfortunately they don’t shed much light on what can be wrong, mainly because they are too long for anyone to inspect and spot any key problems.
Instead could you please try create a small test application that will reproduce the issue for us? In the process you may find the cause of the issue.
Also you may want to try first debugging your application and ensuring that the data is being populated correctly from your class which implements the IMailMergeDataSource interfaces and that the names for the tables being returned each have correct names that match the region names in the document.
Thanks,

I was able to reproduce the problem using your sample code found at: https://reference.aspose.com/words/net/aspose.words.mailmerging/imailmergedatasource/

See the attached zip for source, results, and binaries.

The compiled code against the different versions can be found in the ./bin/debug folder along with the resulting document from each executable.

The source file is test.docx the resulting files are test.results.version.docx

Notice in the 6.5 version the fields in the table get merged, but in the 9.2 version they do not.

Note: the Aspose.total.lic file was not included in the zip but is marked as a local resource in the solution (I purposefully did not include it in the zip for security reasons).

Hi Steven,
Thanks for attaching your sample project. I have taken a look. The behaviour you have described does indeed occur in your project but I don’t believe this to be a bug. Instead it seems to be happening due to a bug being fixed in a later version after 6.5, which is included in 9.2. Let me explain in detail:
In your code at the moment you are using simple mail merge (Execute) not mail merge with regions (ExecuteWithRegions) so only simple merge fields (ones not occuring in a region with TableStart and TableEnd) should be merged. In version 6.5 however even fields that are inside a region are being merged which appears as the wrong behaviour. This was fixed in a later verison which is why this behaviour does not occur in the 9.2 version.
In order to use repeating regions in your project you should use doc.MailMerge.ExecuteWithRegions instead. This does mean you will need to rework your datasource a bit, you will need to have a separate datasource for the simple mail merge fields and call that datasource using Execute and another datasource for the mailmerge regions and use ExecuteWithRegions to merge this.
Also one thing that you need to be aware of, is that your TableStart and TableEnd mergefields don’t actually contain the same name as the tablename you have set out in your code (testTables2). The actual value that is processed by Aspose.Words is found in the field code which can be viewed by pressing ALT+F9 in MS Word. In your case the mergefield name is actually “testTables()”. Please see the screenshots below.
This is what is displayed in MS Word.

but below in the actual field code, “testTables()” is what actually is processed

I have attached the modified the template and attached it along with the new resulting output.
For further details I suggest you have a read through of the mail merge section in the documentation here, this gives full details of working with simple mail merge and mail merge with regions.
If you have any troubles please feel free to ask, we are glad to help.
Thanks,