Solved

Showing af Word-document

Posted on 2002-04-02
11
342 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now