简体   繁体   English

如何使用Delphi XE3以MS Word更改活动打印机

[英]How to change the active printer in MS word using delphi xe3

i open a MS Word document using the following code: 我使用以下代码打开MS Word文档:

  try
  { Open the document}
   WrdApp := CreateOLEObject('Word.Application');
   wrdDoc := 'temp.docx');
  // Wrddoc.SaveAs('temp2.docx');
  except
   on E: Exception do
    begin
     E.Message := 'Could Not Execute MS WORD!';
     raise;
    end;
  end;

And print it using wrdapp.Printout 并使用wrdapp.Printout打印

I have a combobox that has a list of printer names from the computer using the code: 我有一个组合框,其中包含使用以下代码从计算机中获得的打印机名称的列表:

Combobox32.Items.Assign(Printer.Printers);

How do i change the active printer in MS Word to the selected printer in the combobox, so that when i call wrdapp.Printout it will print from the printer selected in the combobox? 如何将MS Word中的活动打印机更改为组合框中的选定打印机,以便在我调用wrdapp.Printout时从组合框中选择的打印机进行打印?

thank you in advance for your help. 预先感谢您的帮助。

You can simply assing WrdApp.ActivePrinter with the name of the printer you want to use. 您可以简单地将WrdApp.ActivePrinter与要使用的打印机的名称关联起来。 In your case, you picjk it from the item selected in the combobox. 在您的情况下,您可以从组合框中选择的项目中进行选择。 For a code example, see this: http://francois-piette.blogspot.be/2014/02/automate-word-document-print-using.html 有关代码示例,请参见: http : //francois-piette.blogspot.be/2014/02/automate-word-document-print-using.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM