?
Solved

Showing af Word-document

Posted on 2002-04-02
11
Medium Priority
?
365 Views
Last Modified: 2010-04-04
How do I show a Word-document in a form, without running the word-exe - in delphi3?

(maybe delphi 4 - but it would be better for me to now how to do it in delphi3).

0
Comment
Question by:hutelihut
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6912667
The only alternative would be to use the Word viewer program from Microsoft.
Showing a Word document needs interpreting the Word file format which is not completely documented.
0
 

Author Comment

by:hutelihut
ID: 6912685
shocking...

I thought it would be easy - like showing it in a OLE-container. I tried to do that, but only the first page was visible...
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6912921
Showing an OLE-Container means starting Word in the background, so i thought that was not an option.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:SteveWaite
ID: 6913183
I think ultimately word/word viewer is required unless doc is saved in another format.

Just in case this helps with the OleContainer method you tried. I get all the doc's pages with this type of thing.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, Menus, StdCtrls, OleServer, Excel2000, OleCtnrs;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OleContainer1: TOleContainer;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  OleContainer1.AllowInPlace := True;
  OleContainer1.AutoActivate := aaGetFocus;
  OleContainer1.CreateObjectFromFile('c:\test.doc', False);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  OleContainer1.SaveAsDocument('c:\test.doc');
end;

end.


Regards,
Steve
0
 

Author Comment

by:hutelihut
ID: 6915086
SteveWaite:

The only problem is, that only the first page is visible in a tOleContainer, otherwise a tOleContainer would be usefull.
0
 
LVL 4

Expert Comment

by:delphi3
ID: 6919966
hutelihut,
I tried the program that was suggested above  by Steve. What you get on the first opener is text of black letters on a delphi olecontainer form colored background. What you need to know is to advance to other  pages is to rightclick of the mouse on the olecontainer so that you get another very small menu. Click to open the 'open' choice. Now with changed view you can edit the document and save it as Steve's program directs with the button one click.  

I did change this line in Steve's program above:
 
OleContainer1.SaveAsDocument('c:\Mytest.doc');

Delphi3
0
 

Author Comment

by:hutelihut
ID: 6920333
When you click at the "Open"-choice, the container "starts" word, and alle the word-menues, and word-buttons and stuff shows up. That is not a great thing, but it can be done by the DoVerb-method.

The program I am making has to show a word-document on a projektor (I am not sure about what it's called in english, but you may ask), so it has be "clean".
0
 

Author Comment

by:hutelihut
ID: 6920335
alle=all

sorry
0
 
LVL 4

Accepted Solution

by:
delphi3 earned 400 total points
ID: 6924327
Hi  hutelihut,

A Word.doc  can also be saved as  a  RichEdit.rtf, or a Html.htm and other forms. However there is
little that can be done to make the graphics that are on either of the above forms 'stick' to the page in
'exact spot' as on the original Word.doc when using the tools of DelphiX.

My Delphi program  is my estimation of what you  might want. What you really need is another
program>> PowerPoint<< that can take a  Word.doc and render it for use in a projector.

To use the program below resave  a Word.doc saved as a  Html.htm. Then use this sample program that uses IE to convert  the text on the Html.htm to a RichEdit.rtf and shows it as having no caption bar.


unit RichEditNoCaptionUnit1;

interface

uses
  WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IniFiles, Clipbrd, ComCtrls, Jpeg, ExtCtrls, ComObj, OleCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    OpenDialog1: TOpenDialog;
    Image1: TImage;
    procedure FormCreate(Sender: TObject);

  private

  public
  end;
var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  IE, Doc, Bod, V: Variant;
  S: string;
  F: TStream;
begin
  Image1.Visible := true;
  Image1.Picture.LoadFromFile(ExtractFilePath(Application.exeName) + 'image001.jpg');
  if OpenDialog1.Execute then
  begin
    F := TFileStream.Create(openDialog1.FileName, fmOpenRead or fmShareDenyNone);
  end;
  try
    SetLength(S, F.Size);
    F.Read(S[1], Length(S));
  finally
    F.Free;
    RichEdit1.Visible := False;
    RichEdit1.lines.add(s);
    IE := CreateOleObject('InternetExplorer.Application');
    IE.Navigate('about:blank', V, V, V, V);

    IE.Visible := False;
    while IE.Busy do
      Application.ProcessMessages;
    Doc := IE.Document;
    Bod := Doc.Body;
    Bod.InnerHTML := RichEdit1.Text;
    RichEdit1.Text := Bod.InnerText;
    IE.Quit;

  end;
  RichEdit1.Visible := True;
  RichEdit1.Lines.SaveToFile(ExtractFilePath(Application.exeName) + 'TextSavedSeenInView' + '.rtf');
  RichEdit1.Color := ClWhite;

end;

end.

Form as text

object Form1: TForm1
  Left = 142
  Top = 26
  BorderIcons = []
  BorderStyle = bsNone
  Caption = 'Borderless RichEdit'
  ClientHeight = 675
  ClientWidth = 760
  Color = clWhite
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 120
  TextHeight = 16
  object Image1: TImage
    Left = 32
    Top = 24
    Width = 105
    Height = 105
    Stretch = True
  end
  object RichEdit1: TRichEdit
    Left = 16
    Top = 160
    Width = 713
    Height = 481
    BorderStyle = bsNone
    Color = clWhite
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -20
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    HideScrollBars = False
    Lines.Strings = (
      '')
    ParentFont = False
    TabOrder = 0
  end
  object OpenDialog1: TOpenDialog
    Filter = 'HTM|*.htm|HTML|*.html'
    Left = 520
    Top = 192
  end
end
 
 
Please notify me if you want the entire package by way of email  (you have my address)  and I will forward it to you. It includes the use of gifs and the gifimage.pas unit.


Delphi3







 
   
0
 
LVL 1

Expert Comment

by:xsoft
ID: 6961521
listening
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9002832
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from Delphi3

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question