Word dokumentumok készítése Delphi
segítségével
Készítsünk Wordben egy plakátot Delphi segítségével.
Alkalmazzunk különböző betűformákat és betűszíneket. A dokumentum több
különbözőképpen formázott bekezdést és beszúrt képeket tartalmazzon.
A formunkra
tervező nézetben a két parancsgomb után, a Servers palettáról helyezzünk
egy-egy WordApplicaton, WordDocument,
WordFont és WordParagraphFormat
elemet. Nevezzük át őket a következő lista alapján:

A tervező nézet:

A program futási képe igen egyszerű:

A létrehozott Word dokumentum:


A program listája:
unit UDWPlakat;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, Word2000, WordXP;
type
TfmDWPlakat = class(TForm)
btPlakat: TButton;
btKilepes: TButton;
svWordAlkalmazas: TWordApplication;
svWordDocument: TWordDocument;
svWordFont: TWordFont;
svWordBekFormat: TWordParagraphFormat;
procedure btKilepesClick(Sender: TObject);
procedure btPlakatClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fmDWPlakat: TfmDWPlakat;
implementation
{$R *.dfm}
procedure TfmDWPlakat.btKilepesClick(Sender: TObject);
begin
Close;
end;
procedure TfmDWPlakat.btPlakatClick(Sender: TObject);
Var Template, NewTemplate, DocumentType, Lathato, ItemIndex, Nev: OleVariant;
FileName: WideString;
Kep, LinkToFile, SaveWithDocument: OleVariant;
begin
With svWordAlkalmazas Do
Begin
Connect; Visible:= True;
Caption:= 'Plakat';
Template:= ''; NewTemplate:= False;
DocumentType:= 0; Lathato:= True;
Documents.Add(Template, NewTemplate, DocumentType, Lathato);
ItemIndex:= 1;
With svWordDocument Do
Begin
ConnectTo(Documents.Item(ItemIndex)); Activate;
With Selection Do
Begin
With Font Do
Begin
Bold:= Integer(True);
Size:= 22;
Color:= clBlue;
Name:= 'ALGERIAN';
Underline:= wdUnderLineSingle;
End;
ParagraphFormat.Alignment:= wdAlignParagraphCenter;
TypeText('Kirándulás Debrecenbe');
Font.Underline:= wdUnderLineNone;
TypeParagraph; TypeParagraph;
End;
With Selection Do
Begin
With Font Do
Begin
Bold:= Integer(False);
Size:= 14;
Color:= clBlack;
Name:= 'Times New Roman';
End;
ParagraphFormat.FirstLineIndent:= 42;
ParagraphFormat.Alignment:= wdAlignParagraphJustify;
TypeText('Kedves osztálytársunk! A tavaszi szünetre egynapos ');
TypeText('kirándulást szervezünk Debrecenbe. Terveink szerint ');
TypeText('busszal mennénk. Időpontja: 2010. április 2-a. ');
TypeText('Indulás 06:30-kor, az iskola melletti parkolóból.');
TypeParagraph; TypeParagraph;
TypeText('A kirándulás programját majd közösen tervezzük meg. ');
TypeText('Javaslatunk szerint városnézéssel, múzeumok és ');
TypeText('nevezetességek megtekintésével töltenénk a napot. ');
TypeText('Ebéd az Aranybika Szállóban lenne. Reggeliről és ');
TypeText('vacsoráról mindenki gondoskodjon. Hazaérkezés 21:30-kor.');
TypeParagraph; TypeParagraph;
ParagraphFormat.FirstLineIndent:= 0;
ParagraphFormat.Alignment:= wdAlignParagraphCenter;
TypeText('Kedvcsinálónak néhány képet láthattok Debrecenről:');
TypeParagraph;
End;
With Selection Do
Begin
FileName:= GetCurrentDir+'\1.jpg';
LinkToFile:= False; SaveWithDocument:= True;
Kep:= InlineShapes.AddPicture(FileName, LinkToFile, SaveWithDocument,
EmptyParam);
TypeParagraph; TypeParagraph;
TypeText('Aranybika Szálló');
TypeParagraph; TypeParagraph;
FileName:= GetCurrentDir+'\2.jpg';
LinkToFile:= False; SaveWithDocument:= True;
Kep:= InlineShapes.AddPicture(FileName, LinkToFile, SaveWithDocument,
EmptyParam);
TypeParagraph; TypeParagraph;
TypeText('Debreceni Egyetem');
TypeParagraph; TypeParagraph;
FileName:= GetCurrentDir+'\3.jpg';
LinkToFile:= False; SaveWithDocument:= True;
Kep:= InlineShapes.AddPicture(FileName, LinkToFile, SaveWithDocument,
EmptyParam);
TypeParagraph; TypeParagraph;
TypeText('Nagytemplom');
TypeParagraph; TypeParagraph;
TypeParagraph; TypeParagraph;
With Font Do
Begin
Bold:= Integer(True);
Size:= 20;
Color:= clRed;
Name:= 'Franklin Gothic Medium';
Underline:= wdUnderLineDouble;
End;
TypeText('Jelentkezni Nagy Tímeánál lehet 2010. március 1-ig');
End;
End;
End;
Nev:= GetCurrentDir+'\Plakat.doc';
svWordDocument.SaveAs(Nev);
svWordFont.Disconnect;
svWordDocument.Disconnect;
svWordAlkalmazas.Quit;
end;
end.
Készítsünk Wordben egy étlapot Delphi segítségével. Az
étlap a hét munkanapjaira legyen érvényes. Tartalmazza az ebédre vonatkozóan a
következőket: leves, köret és feltét, valamint egy hely a savanyúság és a
desszertnek. Az étlapot táblázatos formában jelenítsük meg.
A formunkra tervező nézetben
a két parancsgomb után, a Servers palettáról helyezzünk egy-egy WordApplicaton, WordDocument, WordFont és WordParagraphFormat
elemet. Nevezzük át őket a következő lista alapján:

A tervező nézet:

A program futási képe most is egyszerű:

A létrehozott Word dokumentum:

A
program listája:
unit UDWEtlap;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms,
Dialogs, StdCtrls, Word2000, OleServer;
type
TfmDWEtlap = class(TForm)
btEtlap: TButton;
btKilepes: TButton;
svWordAlkalmazas: TWordApplication;
svWordDocument: TWordDocument;
svWordFont: TWordFont;
svWordBekFormat: TWordParagraphFormat;
procedure btKilepesClick(Sender: TObject);
procedure btEtlapClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
St24=String[24];
var
fmDWEtlap: TfmDWEtlap;
Etlap: Array[1..5,1..6] Of St24=
(('','Hétfő','Kedd','Szerda','Csütörtök','Péntek'),
('Leves','frankfurti leves','zöldségleves',
'gyümölcsleves','paradicsomleves','grízgaluskaleves'),
('Köret','burgonyafőzelék','fánk',
'burgonya','rizs','tarhonyás hús'),
('Feltét','sertéspörkölt','',
'rántott csirkecomb','zöldborsós sertésszelet',''),
('','','',
'uborkasaláta','ecetes paprika','cékla'));
implementation
{$R *.dfm}
procedure TfmDWEtlap.btKilepesClick(Sender: TObject);
begin
Close;
end;
procedure TfmDWEtlap.btEtlapClick(Sender: TObject);
Var Template, NewTemplate, DocumentType, Lathato, ItemIndex, Nev: OleVariant;
I, J: Word;
Oszlop: OleVariant;
Tabla: Table;
begin
With svWordAlkalmazas Do
Begin
Connect; Visible:= True;
Caption:= 'Etlap';
Template:= ''; NewTemplate:= False;
DocumentType:= 0; Lathato:= True;
Documents.Add(Template, NewTemplate, DocumentType, Lathato);
ItemIndex:= 1;
With svWordDocument Do
Begin
ConnectTo(Documents.Item(ItemIndex)); Activate;
PageSetup.Orientation:= 1;
With Selection Do
Begin
With Font Do
Begin
Bold:= Integer(True); Size:= 32; Underline:= wdUnderLineSingle;
End;
ParagraphFormat.Alignment:= wdAlignParagraphCenter;
TypeText('Étlap:');
With Font Do Begin Size:= 24; Underline:= wdUnderLineNone End;
TypeParagraph; TypeParagraph;
ParagraphFormat.Alignment:= wdAlignParagraphCenter;
TypeText('05.31 - 06.04');
TypeParagraph; TypeParagraph;
ParagraphFormat.Alignment:= wdAlignParagraphLeft;
Font.Size:= 16;
End;
With Selection Do
Begin
Tabla:= ActiveDocument.Tables.AddOld(Range,5,6);
With Tabla Do
Begin
For I:= 1 To Rows.Count Do
Begin
Oszlop:= Cell(I,1);
Oszlop.SetWidth(50,wdAdjustProportional);
End;
Borders.InSideLineStyle:= wdLineStyleSingle;
Borders.OutSideLineStyle:= wdLineStyleSingle;
Borders.OutSideLineWidth:= wdLineWidth225pt;
Rows.Item(1).Borders.OutSideLineWidth:= wdLineWidth225pt;
Columns.Item(1).Borders.OutSideLineWidth:= wdLineWidth225pt;
For I:= 1 To 5 Do For J:= 1 To 6 Do With Cell(I,J) Do
Begin
If (I=1) Or (J=1) Then
Begin
Range.Font.Bold:= Integer(True);
Range.Font.Size:= 16;
End Else
Begin
Range.Font.Bold:= Integer(False);
Range.Font.Size:= 13;
End;
Range.Text:= Etlap[I,J];
End;
End;
End;
With Selection Do
Begin
ParagraphFormat.Alignment:= wdAlignParagraphCenter;
With Font Do Begin Size:= 6; Color:= clBlue End;
TypeParagraph;
ParagraphFormat.Alignment:= wdAlignParagraphCenter;
End;
End;
End;
Nev:= GetCurrentDir+'\Etlap.doc';
svWordDocument.SaveAs(Nev);
svWordFont.Disconnect;
svWordDocument.Disconnect;
svWordAlkalmazas.Quit;
end;
end.