Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Automate Word document print using Delphi

Discussion in 'Delphi Programming' started by AdminDF, Mar 7, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member DelphiFan Administrator Staff Member DF Staff

    Automating Microsoft office Word from Delphi is really easy. I already blogged on the subject. This time, I will show you how to select a specific printer in your Delphi application and instruct Word to use that printer.

    Using Delphi, create a new VCL forms application and drop a TComboBox, a TButton and a TWordApplication. Add the unit Printers to the uses clause. In the FormShow event handler, we will fill the combobox with the available printers: 

    Code:
    procedure TForm1.FormShow(Sender: TObject);
    begin
        ComboBox1.Items     := Printer.Printers;
        ComboBox1.ItemIndex := Printer.PrinterIndex;
    end;
    In the button's OnClick event handler, add the following code: 

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    var
        ADoc : _Document;
    begin
        WordApplication1.Connect;
        WordApplication1.Visible := TRUE;
        ADoc := WordApplication1.Documents.Add(emptyParam,
                                            emptyParam, emptyParam, emptyParam);
        WordApplication1.Selection.Text := 'Delphi Fan Rocks !' + #13 +
                                           'http://www.delphifan.com' + #13#10;
        WordApplication1.ActivePrinter := ComboBox1.Text;
        WordApplication1.PrintOut;
        WordApplication1.Disconnect;
    end;
    This code connect the application to Microsoft Word, launching Word if required. It makes Word visible on screen (by default it is not shown). It then insert some nice text in the document. To select the printer Word must use, it is enough to assign the property ActivePrinter with the name of the printer. We pick the name from the combobox. Finally, the document is printed out and the application disconnect from Word.
     
  2. sslin
    Offline

    sslin Guest

    very good
     
  3. falcon2000
    Offline

    falcon2000 Guest

    Wow great share !
     
  4. topst7
    Offline

    topst7 DF Member

    Thank You!
     
  5. scater
    Offline

    scater DF Junior

    RE:

    thanks
     
  6. vxd2000
    Offline

    vxd2000 DF Member

    thanks
     
  7. rhonners
    Offline

    rhonners DF Junior

    RE:

    nice, thanks
     
  8. mario.joker
    Offline

    mario.joker DF Junior

    good. tanks
     
  9. sicmy
    Offline

    sicmy DF Junior

    thankyou

     
     
  10. adisaks
    Offline

    adisaks DF Member

    thank you.
     
  11. Hollibaer
    Offline

    Hollibaer Guest

    Thank you!
     
  12. lallero
    Offline

    lallero DF Member

  13. Zakkoholic
    Offline

    Zakkoholic DF Member

    RE:

    This is really useful !
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block