Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the contents of a word document?

Status
Not open for further replies.

MarvinManuel

Programmer
Apr 28, 2005
11
PH
Hello,
I want to get the contents of a word document using Delphi 2005. Assuming that the document is a plain text only, any samples or helpful links?
Thanks in advance.
 
I do not have delphi 2005 installed at the momment but here is how i would od it using Delphi 6

add the following components to a form
1) TWordDocument (Servers Tab)
2) TwordApplication (Servers Tab)
3) Tbutton
4) TMemo

in the buttonclick event paste the following code


procedure TForm1.Button1Click(Sender: TObject);

var OpenDialog : TOpenDialog;
WordFileName,ReadOnly,Visible : OleVariant;

begin

OpenDialog := TopenDialog.create(Self);

OpenDialog.InitialDir := GetCurrentDir;


// Only Open Files that exists
OpenDialog.Options := [ofFileMustExist];

// Only Word Files
//OpenDialog.Filter :=

ReadOnly := True;
Visible := False;

if OpenDialog.Execute then
begin
WordFileName := OpenDialog.FileName;
WordDocument1.ConnectTo(WordApplication1.Documents.Open(WordFileName,
EmptyParam,
ReadOnly,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
Visible));



Memo1.Lines.Clear;
Memo1.Lines.Text := WordDocument1.Content.Text;


end;




end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top