1

I am trying to load up Mail Merge recipients and their records dynamically in C# using MailMerge interface. I managed to load up the header using MailMerge.CreateDataSource method giving a comma separated string in HeaderRecord. These fields show up when I run Word but the problem is that I can't find any method to populate it's records as well. Currently how I am doing it is making the following csv file and using MailMerge.OpenDataSource method to load this datasource:

Name, Age, Gender, Country, Email
Dummy1, Male, 20, England, dummy1@gmail.com
Dummy2, Male, 21, Spain, dummy2@gmail.com
Dummy3, Male, 22, France, dummy3@gmail.com

My requirement is to load the data without creating any external file, I'm looking for something which would do something similar to:

MailMerge.AddRecord("Dummy1, Male, 20, England, dummy1@gmail.com")
Cœur
  • 37,241
  • 25
  • 195
  • 267
Abdul Jabbar
  • 2,573
  • 5
  • 23
  • 43
  • I can't tell if this is the same question, but the discussion here may be helpful: http://stackoverflow.com/questions/11843694/is-it-possible-to-write-a-word-add-in-or-something-similar-to-provide-a-custom-m/11854434#11854434 –  Dec 27 '14 at 11:53

1 Answers1

1

My advice would be to use fully managed .NET solution with OpenXML. Since OpenXML has steep learning curve, it would probably make sense to look for a toolkit which uses that kind of approach.

I have good experience with Docentric Toolkit. I have been using it for three years now. So here are its pros and cons:

Pros:

  • plain simple Word Add-in for template generation
  • OpenXML based, server side friendly
  • support for images, data-bound graphs, tables
  • conditional elements in templates support for placeholders in headers and footers
  • very fast report generation

Cons:

  • not free
  • support for PDF output is still somewhat limited.

You can see this article on Code Project to get first impression about using this toolkit for merging data (from XML, database, in-memory,...) with appropriate template.