本文介绍了使用 Word Interop 和打印对话框进行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的 C# 代码中打印一个 word 文档.我使用了 12.0.0.0 Word Interop,我想要做的是在文档打印之前弹出打印对话.我不是 100% 确定所有这些的语法,因为我无法让我的代码工作:(有什么想法吗?

I'm trying to print a word doc from my C# code. I used the 12.0.0.0 Word Interop and what i'm trying to do is to get a Print Dialogue pop up before the document prints. I'm not 100% sure of the syntax of all of this as I can't get my code to work :(Any ideas?

提前致谢!

推荐答案

它应该是这样的:

object nullobj = Missing.Value;
doc = wordApp.Documents.Open(ref file,
                             ref nullobj, ref nullobj, ref nullobj,
                             ref nullobj, ref nullobj, ref nullobj,
                             ref nullobj, ref nullobj, ref nullobj,
                             ref nullobj, ref nullobj, ref nullobj,
                             ref nullobj, ref nullobj, ref nullobj);

doc.Activate();
doc.Visible = true;
int dialogResult = wordApp.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref nullobj);

if (dialogResult == 1)
{
    doc.PrintOut(ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                 ref nullobj, ref nullobj);
}

这篇关于使用 Word Interop 和打印对话框进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:19
查看更多