Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi and MS Word

Posted on 2006-11-15
5
Medium Priority
?
201 Views
Last Modified: 2010-04-05
Hi all,

I need to insert lines, tabs and spaces in a word doc.
I want to do that using TWordApllication component.
Example:

    Line1
        Line2
            Line3

   Line4
   Line5

and so on...

regards
0
Comment
Question by:paulo_psa
[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
5 Comments
 
LVL 19

Accepted Solution

by:
Limbeck earned 252 total points
ID: 17953940
0
 
LVL 9

Assisted Solution

by:bernani
bernani earned 248 total points
ID: 17960604
Hi,

You can use this code which will open Word, create a new doc, insert lines and tabs and finally show word with a new document containing this result:


Line 1
      Line 2
            Line 3
Line 4
Line 5



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComObj, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
   
    procedure Button1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1            : TForm1;
  Word             : OLEVariant;
  Sel, Doc         : Variant;

const
vbTab = Chr(9);

implementation

{$R *.DFM}

procedure Return;
begin
Sel.TypeParagraph;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
  Word := CreateOleObject('Word.Application');
  except
  ShowMessage('Cannot start Word !');
  Exit;
  end;

// Word will only be visible when the text is inserted
Doc:=Word.Documents.Add;
Sel:=Word.Selection;

Sel.Font.Name     := 'Times New Roman';
Sel.Font.Size     := 12;
Sel.ParagraphFormat.Alignment := 0; //left aligned

Sel.TypeText('Line 1');
Return;
Sel.TypeText(Text := vbtab + 'Line 2');
Return;
Sel.TypeText(Text := vbtab + vbtab + 'Line 3');
Return;
Sel.TypeText(Text := 'Line 4');
Return;
Sel.TypeText(Text := 'Line 5');
Return;

Word.Visible := True;

end;

end.

_____________________________

Hope this help

PS:

Try to have a look at those pages http://www.djpate.freeserve.co.uk/Automation.htm

You got good infos how to use the compos TWordApplication and others.

See the provided demo: http://www.djpate.freeserve.co.uk/D5Word.zip.

0
 

Expert Comment

by:landscapeEco
ID: 17979353
I think this should be the accepted answer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21133166
Forced accept.

Computer101
EE Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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