I made this small component because I needed mail merge capabilities in an application, and I couldn't find a free component on the internet. The component has been tested in Word'97 and Word 2000.
Via this component, your application can easily create Word documents with application generated contents. The component will open a Word template file (document), and link (merge) the field data from your application to a new generated document.
The component requires Delphi 5, and the Delphi 5 Office Automation Servers. The office automation servers will be used internally by the component.
Suppose that you have a database application with a customer table, a product table, and a sales table. You run a query which shows all customers which have ordered something, but they have not paid there bills yet. Now you want to send them a letter (a real paper letter in an enveloppe) to inform them about there depts.
Follow these steps to accomplish the task:
MailMerge.Columns := 'firstname;lastname;amountdue;employeename'; YourQuery.First; while not YourQuery.EOF do begin MailMerge.Append; MailMerge('firstname') := sqlYourQueryFirstname.Value; // (from a TStringField component) MailMerge('lastname') := sqlYourQueryLastname.Value; MailMerge('employeename') := tblSession.EmployeeName; //etc end;
MailMerge.DocumentName := 'c:\my documents\test merge.doc';
MailMerge.OnStatusMessage := MailMergeStatusMessage; ..... procedure MailMergeStatusMessage(Sender: TObject); begin StatusBar1.SimpleText := TMailMerge(Sender).StatusMessage; end;
MailMerge.Merge;Word will launch, and a temporary datasource document will be generated by the component. The template will opened and merged with the datasource document. The result comes in a new document, and can be accessed via the component's WordDoc interface. (Eg: MailMerge.WordDoc.Print and MailMerge.WordDoc.Close)
A demo application is included. There is no 'register' procedure, just create the component runtime or add your own register function...
My name is Robert van Tilburg and I live in the Netherlands. I'm 21 years old and a computer science student. I learned programming on a MSX-1 homecomputer when I was 10 years old. Now I have various part-time Delphi programming jobs, and experience with Delphi, Turbo Pascal, Basic, 32 bits assembler, C++, C++ Builder, Databases (paradox, Access, SQL Server via BDE and ADO), DirectX, Internet, and desktop applications.
EMail: lothar@lucrasoft.nl