I have a word document (docx format) that I need to populate with data from a dictionary . The key of the dict will be the word field to be populated. I was wondering what is the best way to do this (bookmarks, mail merge fields, etc)? I did a little work with Bookmarks, but I would like to be able to reuse some of the fields (like "first_name" field etc), bookmarks are unique (or I seem to think so).
A few lines of code on how to do this would be really helpful. (c# .net 4.0)
You can make xpath data bindings in a .docx document. A .docx file is just a zipped file in the Office Open XML which can be opened in .Net without third-party libraries.
http://msdn.microsoft.com/en-us/library/system.io.packaging.package.open.aspx
And you can then supply the .docx file with a XML file in your own format. Then the only thing you have to do is to edit the embedded XML file and not the document itself. See:
And a custom tool to do the bindings:
You could properly also use some .Net interaction with Word itself but I can't help you with that.