"Mail Merge" System for XML and Microsoft Word

This project is a sample of how you can merge XML-files with a MS Word template. This makes it easy to create a mailmerge-system. I've created a ActiveX DLL to perform the mailmerge. This makes it very easy to reuse this code in other applications.

An example

When you have a customer-database and you want to write a letter to each of your customers, the only thing you have to do is to create a Word-template and a XML-file with the data of the customers.

This is an example of a XML-file with customer-data:

<?xml version = "1.0" ?>
<!DOCTYPE DOCUMENT [
  <!ELEMENT DOCUMENT (CUSTOMER)*>
  <!ELEMENT CUSTOMER (NAME, ADDRESS, ORDERS)>
  <!ELEMENT NAME (LASTNAME, FIRSTNAME)>
  <!ELEMENT LASTNAME (#PCDATA)>
  <!ELEMENT FIRSTNAME (#PCDATA)>
  <!ELEMENT ADDRESS (STREET, POSTAL, LOCATION)>
  <!ELEMENT STREET (#PCDATA)>
  <!ELEMENT POSTAL (#PCDATA)>
  <!ELEMENT LOCATION (#PCDATA)>
  <!ELEMENT ORDERS (ITEM)*>
  <!ELEMENT ITEM (PRODUCT, PRICE)>
  <!ELEMENT PRODUCT (#PCDATA)>
  <!ELEMENT PRICE (#PCDATA)>
]>

<DOCUMENT>
  <CUSTOMER>
    <NAME>
      <LASTNAME>Braem</LASTNAME>
      <FIRSTNAME>Franky</FIRSTNAME>
    </NAME>
    <ADDRESS>
      <STREET>Jan Van Rijswijcklaan</STREET>
      <POSTAL>2000</POSTAL>
      <LOCATION>Antwerp</LOCATION>
    </ADDRESS>
    <ORDERS>
      <ITEM>
        <PRODUCT>Computer</PRODUCT>
        <PRICE>54.995</PRICE>
      </ITEM>
      <ITEM>
        <PRODUCT>Printer</PRODUCT>
        <PRICE>12.990</PRICE>
      </ITEM>
    </ORDERS>
  </CUSTOMER>

  <CUSTOMER>
      <NAME>
      <LASTNAME>De Smet</LASTNAME>
      <FIRSTNAME>Nathalie</FIRSTNAME>
    </NAME>
    <ADDRESS>
      <STREET>Kruidtuinlaan</STREET>
      <POSTAL>1000</POSTAL>
      <LOCATION>Brussel</LOCATION>
    </ADDRESS>
    <ORDERS>
      <ITEM>
        <PRODUCT>GSM</PRODUCT>
        <PRICE>9.895</PRICE>
      </ITEM>
    </ORDERS>
  </CUSTOMER>
</DOCUMENT>



Click here for larger image

This is an example of a Word-template:

Properties

Property Type Description
DocumentPrefix String The name of each new document is a number. With this property you can specify a prefix to use in the name of document.
Path String The path where the Word documents should be stored
WordTemplate String The name of the Word-template.
XMLFile String The name of the XMLFile.
XMLString String A string with the XML-data.

Methodes

Methode Returns Parameters Description
Execute Boolean / Performs the mailmerge. Returns False when an error occurred.

Downloads

Download demo project - 10 Kb
Download source - 14Kb


Comments

  • web enable

    Posted by Legacy on 09/23/2003 12:00am

    Originally posted by: ali

    hi, cool stuff. can it be use with web based system?
    

    Reply
  • cool tool

    Posted by Legacy on 08/20/2003 12:00am

    Originally posted by: devashi

    this is an awsome tool... quite a novel and nice way of getting around the variable length mail merging difficulties.
    Thanks heaps.

    Reply
  • Run-time Error 429

    Posted by Legacy on 04/29/2003 12:00am

    Originally posted by: Sharon

    I find this tool very useful but for a serious bug in it which has not enabled me to make use of it. I am getting Run time error 429 "ActiveX Component cannot create object". Is there any other dll which I have missed out in the download??. Can you tell me what to do next.

    Reply
  • bug or "how to improve"?

    Posted by Legacy on 07/09/2002 12:00am

    Originally posted by: ribbera

    Otherwise very useful, but with bug. When you try to use <middlename /> or <middlename></middlename> or <middlename> </middlename> (because someone's middle name can be empty) execution ugly breaks.
    Try to fix this.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds