当前位置: 首页>>代码示例>>C#>>正文


C# Application.Quit方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Word.Application.Quit方法的典型用法代码示例。如果您正苦于以下问题:C# Application.Quit方法的具体用法?C# Application.Quit怎么用?C# Application.Quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Word.Application的用法示例。


在下文中一共展示了Application.Quit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WordToPDF

        public static bool WordToPDF(string sourcePath, string targetPath)
        {
            bool result = false;
            Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;
            Microsoft.Office.Interop.Word.Application application = null;

            Microsoft.Office.Interop.Word.Document document = null;
            object unknow = System.Type.Missing;
            application = new Microsoft.Office.Interop.Word.Application();
            application.Visible = false;
            document = application.Documents.Open(sourcePath);
            document.SaveAs();
            document.ExportAsFixedFormat(targetPath, exportFormat, false);
            //document.ExportAsFixedFormat(targetPath, exportFormat);
            result = true;

            //application.Documents.Close(ref unknow, ref unknow, ref unknow);
            document.Close(ref unknow, ref unknow, ref unknow);
            document = null;
            application.Quit();
            //application.Quit(ref unknow, ref unknow, ref unknow);
            application = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            return result;
        }
开发者ID:caengcjd,项目名称:reslove_word,代码行数:30,代码来源:Util.cs

示例2: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     //закриває всі відкриті ворди
     String[] s = textBox1.Text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
     int step = (int) 100/s.Length;
     for (int i = 0; i < s.Length; i++)
     {
         try
         {
             Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
             var wordDocument = appWord.Documents.Open(s[i]);
             s[i] = s[i].Replace(".docx", ".pdf");
             s[i] = s[i].Replace(".doc", ".pdf");
             wordDocument.ExportAsFixedFormat(s[i], WdExportFormat.wdExportFormatPDF);
             wordDocument.Close();
             appWord.Quit();
         }
         catch{}
         progressBar1.Value += step;
     }
     progressBar1.Value = 100;
     MessageBox.Show("Готово", "Звіт про виконання", MessageBoxButtons.OK, MessageBoxIcon.Information);
     textBox1.Clear();
     progressBar1.Value = 0;
 }
开发者ID:AndreFG,项目名称:Utilits,代码行数:25,代码来源:MainForm.cs

示例3: With

        // Usage:
        // using Word = Microsoft.Office.Interop.Word;
        // Action<Word.Application> f = w =>
        // {
        //      var d = w.Documents.Open(@"C:\Foo.docx");
        // };
        // Word1.With(f);
        internal static void With(Action<Word.Application> f)
        {
            Word.Application app = null;

            try
            {
                app = new Word.Application
                {
                    DisplayAlerts = Word.WdAlertLevel.wdAlertsNone,
                    Visible = true
                };
                f(app);
            }
            finally
            {
                if (app != null)
                {
                    if (0 < app.Documents.Count)
                    {
                        // Unlike Excel, Close(...) makes an error when app.Documents.Count == 0
                        // Unlike Excel, Close(...) without wdDoNotSaveChanges shows a prompt for a dirty document.
                        app.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges);
                    }

                    app.Quit();

                    // Both of the following are needed in some cases
                    // while none of them are needed in other cases.
                    Marshal.FinalReleaseComObject(app);
                    GC.Collect();
                }
            }
        }
开发者ID:tatsuya,项目名称:csharp-utility-library,代码行数:40,代码来源:Word1.cs

示例4: Print2

    public static void Print2(string wordfile, string printer = null)
    {
        oWord.Application wordApp = new oWord.Application();
        wordApp.Visible = false;

        wordApp.Documents.Open(wordfile);
        wordApp.DisplayAlerts = oWord.WdAlertLevel.wdAlertsNone;

        System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();

        if (printer == null) // print to all installed printers
        {
            foreach (string p in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                try
                {
                    settings.PrinterName = p;
                    wordApp.ActiveDocument.PrintOut(false);
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex, true);
                }
            }
        }
        else
        {
            settings.PrinterName = printer;
            wordApp.ActiveDocument.PrintOut(false);
        }

        wordApp.Quit(oWord.WdSaveOptions.wdDoNotSaveChanges);
    }
开发者ID:nblaurenciana-md,项目名称:Websites,代码行数:33,代码来源:WordDocServerSidePrinter.cs

示例5: Main

        static void Main(string[] args)
        {
            try
            {
                FileInfo file = new FileInfo(@args[0]);

                if (file.Extension.ToLower() == ".doc" || file.Extension.ToLower() == ".xml" || file.Extension.ToLower() == ".wml")
                {
                    Word._Application application = new Word.Application();
                    object fileformat = Word.WdSaveFormat.wdFormatXMLDocument;

                    object filename = file.FullName;
                    object newfilename = Path.ChangeExtension(file.FullName, ".docx");
                    Word._Document document = application.Documents.Open(filename);

                    document.Convert();
                    document.SaveAs(newfilename, fileformat);
                    document.Close();
                    document = null;

                    application.Quit();
                    application = null;
                }
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Missing parameter: IndexOutOfRangeException {0}", e);
            }
        }
开发者ID:Jeeeeeiel,项目名称:doc2docx,代码行数:29,代码来源:Program.cs

示例6: CompareInWord

    public static void CompareInWord(string fullpath, string newFullpath, string saveName, string saveDir, string author, bool save = false) {
      Object missing = Type.Missing;
      try {
        var wordapp = new Microsoft.Office.Interop.Word.Application();
        try {
          var doc = wordapp.Documents.Open(fullpath, ReadOnly: true);
          doc.Compare(newFullpath, author ?? missing);
          doc.Close(WdSaveOptions.wdDoNotSaveChanges); // Close the original document
          var dialog = wordapp.Dialogs[WdWordDialog.wdDialogFileSummaryInfo];
          // Pre-set the save destination by setting the Title in the save dialog.
          // This must be done through reflection, since "dynamic" is only supported in .NET 4
          dialog.GetType().InvokeMember("Title", BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty,
                                        null, dialog, new object[] {saveName});
          dialog.Execute();
          wordapp.ChangeFileOpenDirectory(saveDir);
          if (!save) {
            wordapp.ActiveDocument.Saved = true;
          }

          wordapp.Visible = true;
          wordapp.Activate();

          // Simple hack to bring the window to the front.
          wordapp.ActiveWindow.WindowState = WdWindowState.wdWindowStateMinimize;
          wordapp.ActiveWindow.WindowState = WdWindowState.wdWindowStateMaximize;
        } catch (Exception ex) {
          Logger.LogException(ex);
          ShowMessageBox("Word could not open these documents. Please edit the file manually.", "Error");
          wordapp.Quit();
        }
      } catch (Exception ex) {
        Logger.LogException(ex);
        ShowMessageBox("Could not start Microsoft Word. Office 2003 or higher is required.", "Could not start Word");
      }
    }
开发者ID:SciGit,项目名称:scigit-client,代码行数:35,代码来源:Util.cs

示例7: PasteTest

        public void PasteTest()
        {
            var fileName = TestFileNames.SourceFile;
            var word = new Application { Visible = false };
            var doc = word.Documents.Open(fileName);

            try
            {
                // ReSharper disable UseIndexedProperty
                var range = doc.Bookmarks.get_Item("Bibliography").Range;
                // ReSharper restore UseIndexedProperty

                var html = Utils.GetHtmlClipboardText("Hello <i>World!</i>");
                Clipboard.SetText(html, TextDataFormat.Html);
                range.PasteSpecial(DataType: WdPasteDataType.wdPasteHTML);

                var destFileName = Path.Combine(Path.GetDirectoryName(fileName),
                    Path.GetFileNameWithoutExtension(fileName) + "-updated" + Path.GetExtension(fileName));
                word.ActiveDocument.SaveAs(destFileName);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.GetMessage());
            }
            finally
            {
                word.Quit(false);
            }
        }
开发者ID:dreikanter,项目名称:refrep,代码行数:29,代码来源:PasteHtmlTest.cs

示例8: Main

        static void Main(string[] args)
        {
            FileInfo file = new FileInfo(@args[0]);

            if (file.Extension.ToLower() == ".docx")
            {
                Console.WriteLine("Starting file name extraction...");

                //Set the Word Application Window Title
                string wordAppId = "" + DateTime.Now.Ticks;

                Word.Application word = new Word.Application();
                word.Application.Caption = wordAppId;
                word.Application.Visible = true;
                int processId = GetProcessIdByWindowTitle(wordAppId);
                word.Application.Visible = false;

                try
                {
                    object filename = file.FullName;
                    Word._Document document = word.Documents.OpenNoRepairDialog(filename);
                    Console.WriteLine("Extracting file names from document '{0}'.", file);

                    //Console.WriteLine("Document has {0} shapes.", document.InlineShapes.Count);
                    if (document.InlineShapes.Count > 0)
                    {
                        foreach (Word.InlineShape shape in document.InlineShapes)
                        {
                            if (shape.Type == Word.WdInlineShapeType.wdInlineShapeEmbeddedOLEObject)
                            {
                                Console.WriteLine("Found file name: {0}", shape.OLEFormat.IconLabel);
                            }
                        }
                    }

                    document.Close();
                    document = null;

                    word.Quit();
                    word = null;
                    Console.WriteLine("Success, quitting Word.");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error ocurred: {0}", e);
                }
                finally
                {
                    // Terminate Winword instance by PID.
                    Console.WriteLine("Terminating Winword process with the Windowtitle '{0}' and the Application ID: '{1}'.", wordAppId, processId);
                    Process process = Process.GetProcessById(processId);
                    process.Kill();
                }
            }
            else
            {
                Console.WriteLine("Only DOCX files possible.");
            }
        }
开发者ID:Softcom,项目名称:FileNameExtractor,代码行数:59,代码来源:Program.cs

示例9: GetComDisplayNames

        public void GetComDisplayNames()
        {
            var wordApp = new Word.Application();

            var docs = wordApp.Documents;

            var names =Impromptu.GetMemberNames(docs);

            Assert.AreEqual(4,names.Count());

            wordApp.Quit();
        }
开发者ID:bbenzikry,项目名称:impromptu-interface,代码行数:12,代码来源:Com.cs

示例10: GetComVar

        public void GetComVar()
        {
            var wordApp = new Word.Application();

            var docs = wordApp.Documents;

            var count = Impromptu.InvokeGet(docs,"Count");

            Assert.AreEqual(0,count);

            wordApp.Quit();
        }
开发者ID:bbenzikry,项目名称:impromptu-interface,代码行数:12,代码来源:Com.cs

示例11: ConvertPPTToDoc

        private static void ConvertPPTToDoc(Options options)
        {
            PPT.ApplicationClass pptApp = new PPT.ApplicationClass();
            pptApp.DisplayAlerts = PPT.PpAlertLevel.ppAlertsNone;

            // make copy so we don't change the original
            string tempPptFilePath = System.IO.Path.Combine(System.IO.Path.GetTempFileName());
            System.IO.File.Copy(options.InPath, tempPptFilePath, true);

            PPT.Presentation pptPresentation = pptApp.Presentations.Open(new FileInfo(tempPptFilePath).FullName, WithWindow: Microsoft.Office.Core.MsoTriState.msoFalse);

            DOC.Application docApp = new DOC.Application();
            var doc = docApp.Documents.Add();

            Console.WriteLine("Converting powerpoint to word");
            ProgressBar progress = new ProgressBar();

            try
            {
                string currentTitle = "";
                string currentSubTitle = "";

                for (int slideNr = 1; slideNr <= pptPresentation.Slides.Count; slideNr++)
                {
                    progress.Report(slideNr / (float)pptPresentation.Slides.Count, "Slide " + slideNr + "/" + pptPresentation.Slides.Count);
                    CopySlide(pptPresentation, doc, options, ref currentTitle, ref currentSubTitle, slideNr);
                }
            }
            finally
            {
                pptPresentation.Close();

                if (System.IO.File.Exists(tempPptFilePath))
                    System.IO.File.Delete(tempPptFilePath);
            }
            //docApp.Visible = true;
            doc.SaveAs(new FileInfo(options.Outpath).FullName);
            doc.Close();

            progress.Dispose();

            Console.WriteLine("Conversion complete, word file written to " + new FileInfo(options.Outpath).FullName);

            try
            {
                docApp.Quit();
                pptApp.Quit();
            }
            catch (Exception)
            {
            }
        }
开发者ID:drake7707,项目名称:PptToDocConverter,代码行数:52,代码来源:Program.cs

示例12: CreateDoc

        private static void CreateDoc(DiplomProject work, HttpResponseBase response)
        {
            Microsoft.Office.Interop.Word.Application app = null;
            string tempfileName = null;
            object falseValue = false;
            var missing = Type.Missing;
            object save = WdSaveOptions.wdSaveChanges;
            object original = WdOriginalFormat.wdOriginalDocumentFormat;
            try
            {
                var url = string.Format("{0}.Export.tasklist.doc", Assembly.GetExecutingAssembly().GetName().Name);
                using (var templateStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(url))
                {
                    object tempdot = tempfileName = SaveToTemp(templateStream);

                    app = new Microsoft.Office.Interop.Word.Application();
                    var doc = app.Documents.Open(ref tempdot, 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);

                    if (doc == null)
                    {
                        throw new ApplicationException("Unable to open the word template! Try to add Launch and Activation permissions for Word DCOM component for current IIS user (IIS_IUSRS for example). Or set Identity to Interactive User.");
                    }

                    FillDoc(doc, work);
                    doc.Save();
                    doc.Close(ref save, ref original, ref falseValue);

                    SaveToResponse(tempfileName, response);
                }
            }
            finally
            {
                if (app != null)
                {
                    object dontSave = WdSaveOptions.wdDoNotSaveChanges;
                    app.Quit(ref dontSave, ref original, ref falseValue);
                }

                if (tempfileName != null)
                {
                    try
                    {
                        File.Delete(tempfileName);
                    }
                    catch (Exception)
                    {
                        //todo: log
                    }
                }
            }
        }
开发者ID:MikhailGogolushko,项目名称:lmsystem,代码行数:51,代码来源:Word.cs

示例13: CloneDocument

        public static void CloneDocument(string FileName, string NewFileName, ProcessDocument ProcessDocumentIn)
        {
            try
            {

                File.Copy(FileName, NewFileName);

                object o = Missing.Value;
                object oFalse = false;
                object oTrue = true;

                Word._Application app = null;
                Word.Documents docs = null;
                Word.Document doc = null;

                object path = NewFileName;

                try
                {
                    app = new Word.Application();
                    app.Visible = false;
                    app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;

                    docs = app.Documents;
                    doc = docs.Open(ref path, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
                    doc.Activate();

                    ProcessDocumentIn(ref doc);

                    doc.Save();
                    ((Word._Document)doc).Close(ref o, ref o, ref o);
                    app.Quit(ref o, ref o, ref o);
                }
                finally
                {
                    if (doc != null)
                        Marshal.FinalReleaseComObject(doc);

                    if (docs != null)
                        Marshal.FinalReleaseComObject(docs);

                    if (app != null)
                        Marshal.FinalReleaseComObject(app);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:Dere969,项目名称:etl-files-am,代码行数:50,代码来源:MicrosoftWord.cs

示例14: btnConvert_Click

        private void btnConvert_Click(object sender, EventArgs e)
        {
            List<string> list = new List<string>();
            SearchFiles(tbDirectory.Text, tbPostFix.Text, list);

            Word = new Microsoft.Office.Interop.Word.Application();

            try
            {
                foreach (string fname in list)
                {
                    DoConvert(fname);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                Word.Quit(ref Nothing, ref Nothing, ref Nothing);
                return;
            }

            Word.Quit(ref Nothing, ref Nothing, ref Nothing);
            MessageBox.Show("convert finish");
        }
开发者ID:ngaut,项目名称:converter,代码行数:24,代码来源:FrmConvert.cs

示例15: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //*************************************** *******
            //来自博客http://blog.csdn.net/fujie724
            //**********************************************
            object oMissing = System.Reflection.Missing.Value;
            //创建一个Word应用程序实例
            Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
            //设置为不可见
            oWord.Visible = false;
           
            //模板文件地址,这里假设在X盘根目录
            object oTemplate = "D://template.dot";
            //以模板为基础生成文档
            Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
            //声明书签数组
            object[] oBookMark = new object[5];
            //赋值书签名
            oBookMark[0] = "beizhu";
            oBookMark[1] = "name";
            oBookMark[2] = "sex";
            oBookMark[3] = "birthday";
            oBookMark[4] = "hometown";
            //赋值任意数据到书签的位置
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = "使用模板实现Word生成";
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = "李四";
            oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "女";
            oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "1987.06.07";
            oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "贺州";
            //弹出保存文件对话框,保存生成的Word
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Word Document(*.doc)|*.doc";
            sfd.DefaultExt = "Word Document(*.doc)|*.doc";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                object filename = sfd.FileName;

                oDoc.SaveAs(ref filename, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);
                oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                //关闭word
                oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
            }

        }
开发者ID:GAHE,项目名称:mo,代码行数:47,代码来源:Form1.cs


注:本文中的Microsoft.Office.Interop.Word.Application.Quit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。