View a Word document in Delphi application

I whant to view a Word document in my application without opening Word. Is it possible and how to do it?

Dag
dikonsultAsked:
Who is Participating?
 
pellelilConnect With a Mentor Commented:
I doubt any has written a "word viwer" component, so that you can view the file without using word. However using OLE/COM you can ask WORD (if installed on the PC) to do the work for you.

A Quick-and-Dirty solution would be to insert a TOleContainer (found in the "Systems" note tab) into an form. Double-click the OleContaine and set it up for "Microsoft Word Documents"
0
 
Mr_PeerapolCommented:
Listening ...
0
 
dikonsultAuthor Commented:
Yes it work with a OLEcontainer and to open the file with OLEcontainer.CreateLinkToFile(filename,false)
but

do you know how to scroll the document?

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
pellelilCommented:
I have never tried it, but I guess that using COM you can ask WORD to perform the scroll.
0
 
raidosCommented:
I suppose OleContainer.OleObject.Application.ActiveWindow.ActivePane.VerticalPercentScrolled := Integer; would scroll it.. for you, not sure though.

Good luck
//raidos
0
 
gandalf_the_whiteCommented:
listening...
0
 
dikonsultAuthor Commented:
Forgive a beginner, but what do you mean with "Listening"
0
 
dikonsultAuthor Commented:
No
OleContainer.OleObject.Application.ActiveWindow.ActivePane.VerticalPercentScrolled := Integer;
did not work, getting a error message telling "Interface not supported"
0
 
gandalf_the_whiteCommented:
listening means that i'm interested in the subject and want to be informed
if there's an answer to the topic
0
 
dikonsultAuthor Commented:
This works

     OleContainer1.CreateObjectFromFile(DataModule1.TestOrderQueryDocument.AsString,false);
     OleContainer1.DoVerb(ovShow);
     TabSheet2.SetFocus;

The TabSheet2.SetFocus; is a quick and dirty method to get rid of the Word menu since I use a TabSheet that can't be locked.

I'm not satisfied since it is a very slow method.
I would rather use
OLEcontainer1.CreateObject(Word.Document.8);
OLEcontainer1.Run;
in Form1.Create
and then open the documents directly in the OLEcontainer.

But I don't know how to open a document without using Word open dialog.
0
 
pellelilCommented:
How about using COM ?

Var
  S, TmpS : string;
begin
  Try
    VarW := CreateOleObject('Word.Basic');
  except
    ShowMessage('Microsoft Word is not installed');
  end;
  VarW.AppShow;
  VarW.FileOpen('somefile.doc');
  ...

This will open word, however I don't know how to use COM to open it into your container, however I guess is possible (somehow)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.