Search code examples
ms-officemailmergeoffice-2010

Is it possible to write a word add-in or something similar to provide a custom mailmerge datasource?


I've a backend system which I want to use as the datasource for MS Word 2010 mailmerge. I've the idea that I should write a word add-in which provides the datasource and is communicating with my backend over webservices.

Is it generally possible to provide a custom datasource with a word add in? Is there a besser solution? Is it possible to do this in C#? Where can I found moar informations about this?

Thanks


Solution

  • The types of data source that Word's out-of-the-box Mailmerge feature can use are well known - e.g.

    1. file-type data sources such as Word documents, plain text files, Excel workbooks and so on,
    2. "DDE" sources (Access, Excel, and MS Query, which in turn expects to work with ODBC connections)
    3. ODBC data sources and
    4. OLE DB data sources (these have to conform to some criteria which AFAIK are not documented, e.g. I think the provider has to implement iCommand)

    To use the built-in Mailmerge, Word has to open the source, and you cannot override OpenDataSource.

    There's no interface that lets you use an ADO.NET data source directly, or a disconnected recordset. If you want to do that, you have to "roll your own" mailmerge. One starting point you could consider is Eric White's series of articles - see, e.g. here .

    Otherwise, you have to ensure that your data source is one of the above things. In the case of ODBC sources, you also have to use a DSN - you can't connect using a DSN-less connection string. You can avoid using a "file" using a System or Machine DSN, but it may actually be easier to distribute a file DSN than create one on the target machine.

    In the case of OLE DB data sources, you have to have a "connection file" of some kind, either a .udl or .odc

    A final note: as far as Word is concerned, "ODBC" is "old" and "OLE DB" is newer. But Microsoft announced some time ago that it was deprecating OLE DB in favour of ODBC. It isn't clear whether that only applies to SQL Server, nor have I seen anything that tells us what Word will support/favour in future. Meanwhile, of course, a lot more documents and data are being stored in cloud locations which may not be accessible using some ODBC/OLE DB drivers/providers.