Solved

Showing af Word-document

Posted on 2002-04-02
11
352 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 100 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 151
Delphi cmd execution 6 67
Can Viruses spread while transferring Binary data with Winsock 2 89
Delphi: making a BW image transparent 10 61
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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