Dear sirs or madams,
Setup:
C#, .NET-Framework console-application (for demo purposes; usually using this inside an ASP.NET application)
Scenario:
I’m currently trying to MailMerge a couple of tables using asposeWordsDocument.MailMerge.ExecuteWithRegions(dataset);
and I’m having multiple tables inside the dataset with different TableNames, but all of them declare the same columnNames (e.g.
- tableNames: “AllProducts”, “RedProducts”, “GreenProducts”, …
- columnNames: “Name”, “PackagingUnit”, “PricePerUnit”), because all of them refer to a List of items of the same class.
As long as all of these tables have at least one data-item, everything is fine. But if one of the tables does not contain any content (header-declarations don’t matter; just content-values), stuff breaks. I’m struggeling with two issues:
-
The console-app declares a couple of products and MailMerges these products into different tables depending on their color (e.g. products with color == Green will be placed inside the “TableStart:GreenProducts”-mailmerge-region). For I did not define any “Blue”-products, I would assume, that the mailmerge-region “TableStart:BlueProducts” does not receive any content - but it does! There will be (as far as I’ve tested) exactly one entry placed inside the “TableStart:BlueProducts”-region that comes from a different table. Is there any issue with my code or is this an unexpected behaviour inside the MailMerge-Engine?
-
This might or might not be an issue resulting from issue 1), because this issue does not seem to be apparent, if all tables do contain values. This time the html-bold-tags, which I’ve wrapped around the values of the Product.Name (before putting them into the data-set; c.f. line 65 in Program.cs) do not render properly inside the “TableStart:YellowProducts”-region.
- Yes, I know, that I could have simply formatted the first columns of the tables inside the word-template to be bold, but that’s besides the point, since the actual use-case is quite a bit more complicated than that and it requires me to be able to conditionally use the bold-format (which works flawlessly as long as all the tables do contains any product/content).
- Then again: If this issue resolves itself by not having issue 1), I’m totally fine with that.
Please find attached a demo-solution including a WordTemplate.docx-file, which is the template for the MailMerge and a Sample_WordResult.docx-file, which I created by (and renamed after) running the console-application. Note: You probably need to modify 3 file-paths, that I’ve declared at the top of Program.cs for the app to run properly.
Aspose_Mergefields_MultipleTables.zip (43.4 KB)
Thanks in advance for any information you can provide on these issues.
Kind regards,
Matthias Heinz