zoukankan      html  css  js  c++  java
  • word打印,和打印预览

    public void Print(object fileName)
            {
                try
                {
                    foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
                    {
                        p.Kill();
                    }
                    this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
                    Object missing = System.Reflection.Missing.Value;
                    object redOlny = false ;
                    this._wordDocument = this._wordApplication.Documents.Open(ref fileName, ref missing, ref redOlny, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

                    //------------------------使用Printout方法进行打印------------------------------
                    object background = false; //这个很重要,否则关闭的时候会提示请等待Word打印完毕后再退出,加上这个后可以使Word所有
                    _wordDocument.PrintOut(ref background, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref

    missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

        ref missing);
                    object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
                    this._wordDocument.Close(ref saveOption, ref missing, ref missing); //关闭当前文档,如果有多个模版文件进行操作,则执行完这一步后接着执行打开Word文档的方法即可
                    saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
                    this._wordApplication.Quit(ref saveOption, ref missing, ref missing); //关闭Word进程
                }
                catch (Exception ex)
                {
                    MessageBox.Show("没安装打印机或者打印机出故障");

                }

                }
            public void PrintViewWord(object fileNmae)
            {
                foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
                {
                    p.Kill();
                }
              Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
              object Missing = System.Reflection.Missing.Value;
              object readOnly = false;
              Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(ref fileNmae, ref Missing, ref readOnly, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);
              wordApp.Visible = true;
              wordDoc.PrintPreview();
            }

  • 相关阅读:
    洛谷P4550 收集邮票 期望dp
    Codeforces Round #748 (Div. 3) G. Changing Brackets
    [Codeforces Round #748 (Div. 3)](https://codeforces.com/contest/1593) F. Red-Black Number 记忆化搜索
    [Codeforces Round #748 (Div. 3)](https://codeforces.com/contest/1593) D2 Half of Same
    HDU 3746 Cyclic Nacklace kmp找循环节
    Codeforces Round #747 (Div.2) D. The Number of Imposters
    Nand2tetris 学习笔记
    怎样解题表
    [省选]知识点板块
    List of Problems to be Solved
  • 原文地址:https://www.cnblogs.com/dachuang/p/9040658.html
Copyright © 2011-2022 走看看