Word dokumentumok készítése Delphi segítségével

 

Plakát

 

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, MessagesSysUtilsVariantsClasses,

  GraphicsControlsForms,
  DialogsStdCtrlsOleServer, Word2000, WordXP;

type
  TfmDWPlakat = class(TForm)
    btPlakatTButton;
    btKilepesTButton;
    svWordAlkalmazasTWordApplication;
    svWordDocumentTWordDocument;
    svWordFontTWordFont;
    svWordBekFormatTWordParagraphFormat;
    procedure btKilepesClick(SenderTObject);
    procedure btPlakatClick(SenderTObject);
  private
    Private declarations }
  public
    { Public declarations }
  end;

var
  fmDWPlakatTfmDWPlakat;

implementation

{$R *.dfm}

procedure TfmDWPlakat.btKilepesClick(SenderTObject);
begin
  Close;
end;

procedure TfmDWPlakat.btPlakatClick(SenderTObject);
Var TemplateNewTemplateDocumentTypeLathatoItemIndexNevOleVariant;
    FileNameWideString;
    KepLinkToFileSaveWithDocumentOleVariant;
begin
  With svWordAlkalmazas Do
  Begin
    ConnectVisible:= True;
    Caption:= 'Plakat';
    Template:= ''; NewTemplate:= False;
    DocumentType:= 0; Lathato:= True;
    Documents.Add(TemplateNewTemplateDocumentTypeLathato);
    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;
        TypeParagraphTypeParagraph;
      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.');
        TypeParagraphTypeParagraph;
        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.');
        TypeParagraphTypeParagraph;
        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:= FalseSaveWithDocument:= True;
        Kep:= InlineShapes.AddPicture(FileNameLinkToFileSaveWithDocument,
                                      EmptyParam);
        TypeParagraphTypeParagraph;
        TypeText('Aranybika Szálló');
        TypeParagraphTypeParagraph;
        FileName:= GetCurrentDir+'\2.jpg';
        LinkToFile:= FalseSaveWithDocument:= True;
        Kep:= InlineShapes.AddPicture(FileNameLinkToFileSaveWithDocument,
                                      EmptyParam);
        TypeParagraphTypeParagraph;
        TypeText('Debreceni Egyetem');
        TypeParagraphTypeParagraph;
        FileName:= GetCurrentDir+'\3.jpg';
        LinkToFile:= FalseSaveWithDocument:= True;
        Kep:= InlineShapes.AddPicture(FileNameLinkToFileSaveWithDocument,
                                      EmptyParam);
        TypeParagraphTypeParagraph;
        TypeText('Nagytemplom');
        TypeParagraphTypeParagraph;
        TypeParagraphTypeParagraph;
        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.

 

Étlap

 

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, MessagesSysUtilsVariantsClasses,

  GraphicsControlsForms,
  DialogsStdCtrls, Word2000, OleServer;

type
  TfmDWEtlap = class(TForm)
    btEtlapTButton;
    btKilepesTButton;
    svWordAlkalmazasTWordApplication;
    svWordDocumentTWordDocument;
    svWordFontTWordFont;
    svWordBekFormatTWordParagraphFormat;
    procedure btKilepesClick(SenderTObject);
    procedure btEtlapClick(SenderTObject);
  private
    Private declarations }
  public
    { Public declarations }
  end;

  St24=String[24];

var
  fmDWEtlapTfmDWEtlap;
  EtlapArray[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(SenderTObject);
begin
  Close;
end;

procedure TfmDWEtlap.btEtlapClick(SenderTObject);
Var TemplateNewTemplateDocumentTypeLathatoItemIndexNevOleVariant;
    I, J: Word;
    Oszlop: OleVariant;
    TablaTable;
begin
  With svWordAlkalmazas Do
  Begin
    ConnectVisible:= True;
    Caption:= 'Etlap';
    Template:= ''; NewTemplate:= False;
    DocumentType:= 0; Lathato:= True;
    Documents.Add(TemplateNewTemplateDocumentTypeLathato);
    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;
        TypeParagraphTypeParagraph;
        ParagraphFormat.Alignment:= wdAlignParagraphCenter;
        TypeText('05.31 - 06.04');
        TypeParagraphTypeParagraph;
        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.