• 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();
            }

  • 相关阅读:
    实验报告五
    实验报告四
    树莓派系统安装和调试
    Linux内核分析——扒开系统调用的三层皮(下)
    Linux内核分析——第二章 从内核出发
    Linux内核分析——第一章 Linux内核简介
    Linux内核分析——扒开系统调用的三层皮(上)
    Linux内核分析——构造一个简单的Linux系统MenuOS
    Linux内核分析——操作系统是如何工作的
    Linux内核分析——计算机是如何工作的
  • 原文地址:https://www.cnblogs.com/dachuang/p/9040658.html
Copyright © 2020-2023  润新知