1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

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 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
    Online

    sslin Guest

    very good
     
  3. falcon2000
    Online

    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
    Online

    Hollibaer Guest

    Thank you!
     
  12. lallero
    Offline

    lallero DF Member

  13. Zakkoholic
    Offline

    Zakkoholic DF Member

    RE:

    This is really useful !
     

Share This Page