예제 #1
0
 public static void realaseProcessExit(Word::Application app)
 {
     app.Quit();
     //if (CommonVariable.range != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.range);
     //    CommonVariable.range = null;
     //}
     //if (CommonVariable.mark != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.mark);
     //    CommonVariable.mark = null;
     //}
     //if (CommonVariable.marks != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.marks);
     //    CommonVariable.marks = null;
     //}
     //if (CommonVariable.link != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.link);
     //    CommonVariable.link = null;
     //}
     //if (CommonVariable.links != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.links);
     //    CommonVariable.links = null;
     //}
     //if (CommonVariable.doc != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.doc);
     //    CommonVariable.doc = null;
     //}
     //if (CommonVariable.docs != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.docs);
     //    CommonVariable.docs = null;
     //}
     //CommonVariable.app.Quit();
     //if (CommonVariable.app != null)
     //{
     //    Marshal.ReleaseComObject(CommonVariable.app);
     //    CommonVariable.app = null;
     //}
     //GC.Collect();
 }
예제 #2
0
        protected override void Execute(NativeActivityContext context)
        {
            app = new Word::Application();
            try
            {
                string filePath = PathUrl.Get(context);

                Word::Documents docs = app.Documents;
                app.Visible       = IsVisible;
                app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;

                if (NewDoc)
                {
                    docs.Add();
                }
                else
                {
                    if (!File.Exists(PathUrl.Get(context)))
                    {
                        // 文件不存在,请检查路径有效性
                        SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("xFileNotExist"));
                        CommonVariable.realaseProcessExit(app);
                    }
                    else
                    {
                        docs.Open(filePath);
                    }
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(app);
            }
            if (Body != null)
            {
                context.ScheduleAction(Body, app, OnCompleted, OnFaulted);
            }
        }