Working with Word Document in Delphi

Working with Word Document in Delphi

In this example, we will explain how to control the Microsoft Word document with Delphi and share source code. You can also use these commands to open a Word document, insert a string into a file, save and close the file, and much more. 

 

A computer that does not have MS-Word installed is very rare. For text processing and documents, most of us use Microsoft Word on our computer. Therefore, it is sometimes very logical to use the infrastructure of our program. For example, it can be used when you need to print out a report in your application. Since many people are familiar with administrative affairs, it can be much easier to use such output. 

 

Crystal reports as a reporting tool instead of MS-Word or some other reporting solutions. You can use Quickreport, FastReport, Preport, Reportbuilder, and others. Most people simply keep small documents and notes in MS-Word with their own efforts and keep names and phone numbers. So why don't we use MS-Word to produce output instead of relying on some reporting solutions?

 

 

uses ComObj; 
var Word: Variant;

remember to remember comobj to uses.

procedure TForm1.Button1Click(Sender: TObject); 
begin 
Word:=CreateOLEObject('Word.Application'); 
Word.Visible:=True; 
Word.Documents.Open(GetCurrentDir+'\Test.doc'); 
Word.WordBasic.Insert('Greatis '); 
Word.Documents.Save; 
end; 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
Word.Documents.Close; 
end;

These codes allow you to open a Word document and insert it into it and save it to close it. What about other procedures?..

 

Use MS Word in a Delphi application from this link.

 

You can access Delphi sample projects and source codes here.

You can comment on the topics you are curious about and what you want to ask. Thanks.