none
How to do a mail merge using DocumentFormat.OpenXml.Wordprocessing.MailMerge

    คำถาม

  • I have a set of existing Word templates with simple text merge fields. I would like to automate the process of merging existing data files with these templates to produce multiple documents using Open XML from a vb.net program.

    I have found reference to the DocumentFormat.OpenXml.Wordprocessing.MailMerge class but have not been able to find any examples of how to use this to do a mail merge.  Can you refer me to any examples of how to use this?  Thanks.


    Mary Leathem

    11 เมษายน 2555 19:36

คำตอบ

  • I suppose you want to do "data driven document generation". To do that you will need a means to somehow mark/tag placeholders on a template document. Yes, one way to do this is by using merge fields, but there are also other techniques. I think a much better way to do mail merge is by using content controls, which can even be data bound to an embedded "Custom XML Part". In my oppinion merge fields are not very flexible oppinion because you can only use them to mark placeholders. But what about repeating content (e.g. rendering product list)? In such a case people usually combine merge fields with bookmarks which I find very cumbersome.

    If you are going to create your own mail merge solution I would suggest you to use content controls (Ms Word 2007+) since they are very flexible. In any case when using Open XML SDK you will need to learn a lot about Open XML (standard) and creating such a solution is very tedious and error prone. I think that a lot of people create a Open XML SDK solution that sometimes generates a corrupt document. This is simply because Open XML SDK doesn't provide a higher abstraction APIs like for example when using Office COM.

    I think that before creating your own solution you should check for a mail-merge component/tool/product that already exist. One such product is Docentric which is not a free product but you will be able to solve your problem with almost no coding. It has its own Add-In for MS Word which greately simplifies the temlate design/creation and it is also capable of much more like: nested tables/hierarchies, placeholders in headers, footers, multiple sections, List tag (repeating sections), data-bound images, charts, hyperlinks, (sub)document merging, ...

    • ทำเครื่องหมายเป็นคำตอบโดย Tom_Xu_WXModerator 17 เมษายน 2555 5:07
    12 เมษายน 2555 10:55

ตอบทั้งหมด

  • I suppose you want to do "data driven document generation". To do that you will need a means to somehow mark/tag placeholders on a template document. Yes, one way to do this is by using merge fields, but there are also other techniques. I think a much better way to do mail merge is by using content controls, which can even be data bound to an embedded "Custom XML Part". In my oppinion merge fields are not very flexible oppinion because you can only use them to mark placeholders. But what about repeating content (e.g. rendering product list)? In such a case people usually combine merge fields with bookmarks which I find very cumbersome.

    If you are going to create your own mail merge solution I would suggest you to use content controls (Ms Word 2007+) since they are very flexible. In any case when using Open XML SDK you will need to learn a lot about Open XML (standard) and creating such a solution is very tedious and error prone. I think that a lot of people create a Open XML SDK solution that sometimes generates a corrupt document. This is simply because Open XML SDK doesn't provide a higher abstraction APIs like for example when using Office COM.

    I think that before creating your own solution you should check for a mail-merge component/tool/product that already exist. One such product is Docentric which is not a free product but you will be able to solve your problem with almost no coding. It has its own Add-In for MS Word which greately simplifies the temlate design/creation and it is also capable of much more like: nested tables/hierarchies, placeholders in headers, footers, multiple sections, List tag (repeating sections), data-bound images, charts, hyperlinks, (sub)document merging, ...

    • ทำเครื่องหมายเป็นคำตอบโดย Tom_Xu_WXModerator 17 เมษายน 2555 5:07
    12 เมษายน 2555 10:55