示例#1
0
 public void Close()
 {
     try
     {
         if (wordDoc != null)
         {
             object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
             wordDoc.Close(ref saveOption, ref missing, ref missing);
         }
         if (wordApp != null)
         {
             object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
             wordApp.Quit(ref saveOption, ref missing, ref missing);
         }
         if (wordApp != null)
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
             wordApp = null;
         }
     }
     catch (Exception e1)
     {
         Log.Error("DocOpen exception, and close exception. " + e1.Message);
     }
     finally
     {
         wordDoc = null;
         wordApp = null;
         closeProc(filename);
         GC.Collect();
     }
 }
示例#2
0
        public bool Quit()
        {
            try
            {
                object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
                oWord.Quit(ref saveOption, ref Nothing, ref Nothing);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                oWord = null;
                oDoc  = null;
                odoc  = null;
                GC.Collect();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }