office parnet ile worde yazı yazdırma

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
berken
Üye
Mesajlar: 208
Kayıt: 07 Ara 2005 04:27
Konum: Van

office parnet ile worde yazı yazdırma

Mesaj gönderen berken »

arkadaslar wordde var olan taslak içine istediğim kısma delphiden nasıl yaız gönderebilirm
.. mesela taslakta ustte bilgiler var..
asagıda tablo var.. tabloya istediğim karenın içine naasıl bilgi yazdırırım..
bir çeşit worde takla attırma..
İnsanca.... Pek insanca....
Kullanıcı avatarı
Master_Yoda
Üye
Mesajlar: 35
Kayıt: 13 Ara 2005 12:57

Mesaj gönderen Master_Yoda »

S.A.
Bu işleme genel olrak mailmerge deniyor.
database e bağlanarak msword bu işi kendi üzerinde halledebiliyor aslında.

ben openoffice üzerinde yaptım ama orada swx dosyası aslında bir zip ve içinde xml olarak içerik ve format dosyaları barındıryor. Böyle olunca açıp okuyup yazmak kolay standart xmldom componentleri ile olduydu.

mswordde ise bu sorun daha ciddi bir sorun. dinamik word documanı üretirkenfarklı iki yöntem kullanabilirsin.

ilk olarak dökümanın tamamını ole ile worde oluşturta bilirsin.
ikinci yol ise yine ole/activex kullanrak word e dökümanı açtırıp güncelleme yapabilirsin ..

Aşağıda ikinciye çok ittirme bir örnek var burda dökümanın içinde ne olduğu nereye ne yazdırılacağı belli bir durum söz konusu esnek bir yapı değil ama işe yarıyor tabiki .. Ve activex yerine ole kullanılmış durumda ..
örnekteki x.move ... gibi komutların neler olduğunu msword de vb macro yazarak görebilirsin. yada record macro ile ama birebir aynı değil .
ole yerine delphi içindeki msword application server nesnesini de kullanabilirsin ..

Kod: Tümünü seç


var
  x: Variant;
  s,
  fn : String;
  px : String ;
Begin
 px:=ExtractFilePath(Application.ExeName);
 fn:=px+'belgeler\'+Trim(STKPASBASISLEMNO.AsString)+'_ImalatFormu.doc';
 Try
 if FileExists(fn) And
   (MessageDlg(Fn+' Var üzerine yazılsın mı?',mtConfirmation,[mbYes,mbNo],0)=mrNo) Then Exit;
 ForceDirectories(px+'belgeler\');
 x:=CreateOleObject('Word.Application');
 Try
   x.documents.Open(px+'ImalatFormu.doc');
   x.Selection.MoveDown(5,4);
   x.Selection.TypeText(STKPASBASISLEMNO.AsString);
   x.Selection.MoveDown(5,3);
   x.selection.TypeText(STKPASBASFIRMA.AsString);
   x.Selection.MoveDown(5,2);
   STKPASMAD.First;
   While Not STKPASMAD.Eof Do begin
     s:=s+STKPASMADURUNADI.AsString+#13#10;
     STKPASMAD.NEXT;
   End;
   x.selection.TypeText(s);
   deletefile(fn);
   x.ActiveDocument.SaveAs(fn);
 Finally
   x.quit;
 End;
 Sleep(2000);
 Finally
 ShellExecute(0,'open',PChar(fn),nil,nil,SW_SHOW);
 End;
end;
Kullanıcı avatarı
Master_Yoda
Üye
Mesajlar: 35
Kayıt: 13 Ara 2005 12:57

Mesaj gönderen Master_Yoda »

Birde dinamik database dökümantasyonu için bir program yazmıştım .. informix için neyse. burada 1. yönteme güzel bir örnek var activex in methodları dinamik olmayan çok sayıda ve var parametre içerdiğinden kullanımı zor programda basit bir lib oluşmutu işleri kolaylaştıran ilgilenen arkadaşlara faydası olur delphi 6 da yazılmıştı:

Kod: Tümünü seç


Procedure NewDoc(wd: TWordApplication;Header,Footer:String);
Var
 s,x,vT,vF : OleVariant;
Begin
  s:='';
  vF:=False;
  vT:=True;
  x:=0;
  wd.Documents.Add(s,vF,x,vT);
   With wd Do Begin

   If ActiveWindow.View.SplitSpecial <> wdPaneNone
   Then ActiveWindow.Panes.Item(2).Close;
   If (ActiveWindow.ActivePane.View.Type_ = wdNormalView) Or
      (ActiveWindow.ActivePane.View.Type_ = wdOutlineView)
   Then ActiveWindow.ActivePane.View.Type_ := wdPrintView ; // wdOnlineView; //  ;
   ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader;
   Selection.TypeText(Header);
   With Selection.ParagraphFormat Do Begin
        Borders.item(wdBorderLeft).LineStyle := wdLineStyleNone;
        Borders.item(wdBorderRight).LineStyle := wdLineStyleNone;
        Borders.Item(wdBorderTop).LineStyle := wdLineStyleNone;
        With Borders.item(wdBorderBottom) Do Begin
            LineStyle := wdLineStyleSingle;
            LineWidth := wdLineWidth050pt;
        End;
        With Borders Do Begin
            DistanceFromTop := 1;
            DistanceFromLeft := 4;
            DistanceFromBottom := 1;
            DistanceFromRight := 4;
            Shadow := False;
        End;
    End;
    With Options Do Begin
        DefaultBorderLineStyle := wdLineStyleSingle;
        DefaultBorderLineWidth := wdLineWidth050pt;
    End;
    x:=wdAlignPageNumberCenter;
    Selection.HeaderFooter.PageNumbers.Add(x,vT);
    If Selection.HeaderFooter.IsHeader
    Then ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageFooter
    Else ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageHeader;
    Selection.TypeText(Footer);
    With Selection.ParagraphFormat Do Begin
        Borders.item(wdBorderLeft).LineStyle := wdLineStyleNone;
        Borders.item(wdBorderRight).LineStyle := wdLineStyleNone;
        With Borders.item(wdBorderTop) Do Begin
            LineStyle := wdLineStyleSingle;
            LineWidth := wdLineWidth050pt;
        End;
        Borders.Item(wdBorderBottom).LineStyle := wdLineStyleNone;
        With Borders Do Begin
            DistanceFromTop := 1;
            DistanceFromLeft := 4;
            DistanceFromBottom := 1;
            DistanceFromRight := 4;
            Shadow := False
        End
    End;
    With Options DO Begin
      DefaultBorderLineStyle := wdLineStyleSingle;
      DefaultBorderLineWidth := wdLineWidth050pt;
    End;
    ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument;
   End;
End;


Procedure SetStyle(wd: TWordApplication;st:String);
Var
  s,xx:OleVariant;
Begin
   s:=st;
   xx:=wd.ActiveDocument.Styles.Item(s);
   wd.Selection.Set_Style(xx);
End;

Procedure WriteParagraph(wd: TWordApplication;st:String);
Begin
  wd.Selection.TypeText(st);
  wd.Selection.TypeParagraph;
End;

Procedure MakeTable(wd:TWordApplication;
                    ColNames: Array Of String;
                    ColWidths: Array Of Single);
Var
  Cols:Integer;
x,s,i1,Format, ApplyBorders, ApplyShading, ApplyFont, ApplyColor,
ApplyHeadingRows,ApplyLastRow, ApplyFirstColumn,
ApplyLastColumn, AutoFit,vt ,cell: OleVariant;
i : Integer;
Begin
  Cols:=High(ColNames)+1; // Zero  bases !!
  With wd Do Begin
   Format:=wdTableFormatGrid8;
   ApplyBorders:= True;
   ApplyShading:=True;
   ApplyFont:=True;
   ApplyColor:=True;
   ApplyHeadingRows:=True;
   ApplyLastRow:=False;
   ApplyFirstColumn:=True;
   ApplyLastColumn:=False;
   AutoFit:=True;
   vt:=True;
   s:=wdWord9TableBehavior;
   i1:=wdAutoFitFixed;
   ActiveDocument.Tables.Add(wd.selection.Range,2,cols,s,i1);
       Selection.Tables.item(1).AutoFormat(Format, ApplyBorders, ApplyShading, ApplyFont, ApplyColor,
       ApplyHeadingRows,ApplyLastRow, ApplyFirstColumn,
       ApplyLastColumn, AutoFit);
    Selection.Tables.Item(1).Rows.Item(1).HeadingFormat := vT;

   For i:=1 To Cols Do
      Selection.Tables.Item(1).Columns.Item(i).Set_Width(ColWidths[i-1]*28.35);

   i1:=1;
   cell:=wdCell;
   x:=wdMove;
   For i:=1 To Cols Do Begin
     Selection.TypeText(colNames[i-1]);
     Selection.MoveRight(cell,i1,x);
   End;
  End;

End;

Procedure WriteToTable(wd: TWordApplication;S:String);
Var
 Cell,i1,x:OleVariant;
Begin
  i1:=1;
  cell:=wdCell;
  x:=wdMove;
  wd.Selection.TypeText(s);
  wd.Selection.MoveRight(cell,i1,x);
End;


Procedure EndTable(Wd:TWordApplication);
Var
 Line,i1,x:OleVariant;
Begin
  i1:=1;
  Line:=wdLine;
  x:=wdMove;
  wd.Selection.Tables.Item(1).Rows.Last.Delete;
  wd.Selection.MoveDown(Line,i1,x);
End;

Procedure SaveToFile(Wd:TWordApplication;FileName:String);
Var
  fn,ff,lockcomment,pass,addtorecentfiles,wrpass,readonlyrecommended,
  emmbedttf,savenativepicfmt,saveforms,saveasAOCELetter: OleVariant;
Begin
  fn:=FileName;
  ff:=wdFormatDocument;
  lockcomment:=False;
  pass:='';
  Addtorecentfiles:=True;
  wrpass:='';
  Readonlyrecommended:=False;
  emmbedttf:=false;
  savenativepicfmt:=False;
  saveforms:=False;
  saveasAOCELetter:=False;
  wd.ActiveDocument.SaveAs(fn,ff,lockcomment,pass,addtorecentfiles,wrpass,readonlyrecommended,emmbedttf,savenativepicfmt,saveforms,saveasAOCELetter);
End;
Tabi çok esnek ve genel amaçlı değil ama daha önceki koddan daha genel ..
kullanım örneği de olması açısından biraz da database dökümantasyonundan seçmece kodları ekliyorum:

Kod: Tümünü seç


Var
 Tables : TStringList;
 i,c    : Integer;
 st     : String ;
 ct     : Integer;
 si     : Integer;
begin
 dbx.Params.Clear;
 dbx.Params.Add('USER NAME='+edUser.Text);
 dbx.Params.Add('PASSWORD='+edPass.Text);
 dbx.Connected:=true;
 Tables := TStringList.Create;
 NewDoc(wd,dbAlias.Text+' Veri Tabanı Yapısı','Dipnot');
 SetStyle(wd,'Heading 1');
 WriteParagraph(wd,'Tablolar');


 Try
   Session.GetTableNames('dbx','',False,false,Tables);
   pb.max:=Tables.Count;
   pb.Visible:=true;
   For i:=0 to Tables.Count-1 do Begin
     SetStyle(wd,'Heading 2');
     WriteParagraph(wd,UpperCase(Tables[i])+' Tablosu');
     sb.SimpleText:=Tables[i];
     pb.position:=i;
     Application.ProcessMessages;
     qi.parambyname('tn').AsString:=Tables[i];
     qi.open;
     si:=0;
     While Not qi.Eof do Begin
       if si=0 Then Begin
         SetStyle(wd,'Heading 3');
         WriteParagraph(wd,'İndex Tanımları');
         MakeTable(wd,['İndex Adı','Tipi','Alanlar'],[3,1.5,6]);
       End;

       inc(si);
       st:='';
       for c:=1 to 13 Do begin
         if qi.FieldByName('col'+inttostr(c)).isNull Then Break;
         if st<>'' Then st:=st+',';
         st:=st+qi.FieldByName('col'+inttostr(c)).AsString;
         if qi.FieldByName('part'+inttostr(c)).AsInteger<0
         Then st:=st+' Desc';
       End;
       WriteToTable(wd,qi.FieldByName('idxname').AsString);
       if qi.FieldByName('idxtype').AsString='U'
       Then WriteToTable(wd,'Unique')
       Else WriteToTable(wd,'Dublicate');
       WriteToTable(wd,st);
       qi.Next;
     End;
     if st<>'' Then EndTable(wd);
     qi.close;
     SetStyle(wd,'Heading 3');
     WriteParagraph(wd,'Tablo Alanları');
     MakeTable(wd,['Alan Adı','Tipi','Null','Açıklama'],[3,2,1,6]);
     qc.parambyname('tn').AsString:=Tables[i];
     qc.open;
     While Not qc.Eof Do Begin
      ct:=qc.fieldByName('coltype').AsInteger;
      si:=qc.FieldByName('collength').AsInteger;
      st:='('+inttostr(ct)+')';
      Case ct and 255 of
        0:st:='Char('+inttostr(si)+')';
        1:st:='SmallInt';
        2:st:='Integer';
        3:st:='Float';
        5:st:='Decimal('+inttostr(si shr 8)+','+inttostr(si and $ff)+')';
        6:st:='Serial';
        7:st:='Date';
       10:st:='DateTime Year To Minute';
       13:st:='Varchar('+inttostr(si)+')';
       12:st:='Text In Table';
      End;
      WriteToTable(wd,qc.FieldByName('colname').AsString);
      WriteToTable(wd,st);
      if ct And 256 = 256
      Then WriteToTable(wd,'No')
      Else WriteToTable(wd,'Yes');
      WriteToTable(wd,'..');
      qc.Next;
     End;
     qc.Close;
     EndTable(wd);

     qt.ParamByName('tn').AsString:=Tables[i];
     qt.Open;
     si:=0;
     st:='';
     While Not qt.Eof Do Begin
       if si=0 Then Begin
         SetStyle(wd,'Heading 3');
         WriteParagraph(wd,'Tablo Triggerları');
       End
       Else if si<>qt.FieldByName('trigid').AsInteger
            Then Begin
               WriteParagraph(WD,st);
               WriteParagraph(wd,' ');
               st:='';
            End;
       Si:=qt.FieldByName('trigid').AsInteger;
       st:=st+PrepStr(qt.FieldByName('data').AsString);
       qt.Next;
     End;
     if si<>0 Then Begin
       WriteParagraph(WD,st);
       WriteParagraph(wd,' ');
       st:='';
     End;
     qt.Close;
   End;
   qp.Open;
   si:=0;
   sb.SimpleText:='Procedures..';
   Application.ProcessMessages;
   st:='';
   While Not qp.Eof Do Begin
     if si=0 Then Begin
       SetStyle(wd,'Heading 1');
       WriteParagraph(wd,'Stotred Procedures');
     End;
     if si<>qp.FieldByName('procid').AsInteger Then Begin
       if st<>'' Then WriteParagraph(wd,st);
       st:='';
       SetStyle(wd,'Heading 2');
       WriteParagraph(wd,'Procedure '+qp.FieldByName('procname').AsString);
     End;
     Si:=qp.FieldByName('procid').AsInteger;
     st:=st+PrepStr(qp.FieldByName('data').AsString);
     qp.Next;
   End;
   qp.Close;
   if si<>0 Then WriteParagraph(wd,st);
   SaveToFile(wd,edFileName.Text);
 Finally
   Tables.Free;
   pb.Visible:=false;
   dbx.Connected:=false;
   sb.SimpleText:='Ok..';
 End;
end;

NOT: İlgilenen olursa informix system tablolarından database yapısını (tablo,kolon,index, trigger stored proc v.s. ) nasıl çekildiğini anlatırım..
Kullanıcı avatarı
berken
Üye
Mesajlar: 208
Kayıt: 07 Ara 2005 04:27
Konum: Van

Mesaj gönderen berken »

ilginize tesekkur ediyorumm .. verdiğiniz kodları çalıştırmaya calışıyorum.
bazı hatalar veriyor bende . ms officexp ve d7 kullanıyorum.. bakalım nasıl çıkacam içinden..
incelemedeyim yani..
İnsanca.... Pek insanca....
Hakan Can
Üye
Mesajlar: 634
Kayıt: 04 Mar 2005 04:27
Konum: Ankara

Mesaj gönderen Hakan Can »

Ben Word içine daha önceleri Word'ün bir özelliğini kullanarak veritabanından bilgi gönderiyordum. Word'un "Adres Mektup Birleştirme" özelliğinden faydalanmıştım. Aslında oldukça kullanışlı bir yöntem.
İlgilenirsen incelemeni tavsiye ederim.

İyi çalışmalar.
Kullanıcı avatarı
tuanna
Üye
Mesajlar: 582
Kayıt: 06 Ara 2004 05:01
Konum: Ankara
İletişim:

Mesaj gönderen tuanna »

bu konunun devaamı olaarak sunu sormak istiyordum

word sayfasında sutunlar eklemek ve resimler eklemek istiyorum...
Cevapla