Beispiel #1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag];
            Application        wordApp  = property.GetValue(context.DataContext) as Application;

            try
            {
                string textContent = TextContent.Get(context);
                Int32  newLine     = NewLine.Get(context);

                for (int i = 0; i < newLine; i++)
                {
                    wordApp.Selection.TypeParagraph();
                }
                wordApp.Selection.TypeText(textContent);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(wordApp);
            }

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Beispiel #2
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag];
            Application        wordApp  = property.GetValue(context.DataContext) as Application;

            try
            {
                if (_Copy)
                {
                    wordApp.Selection.Copy();
                }
                if (_Paste)
                {
                    wordApp.Selection.Paste();
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(wordApp);
            }

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Beispiel #3
0
        private void OnCompleted(NativeActivityContext context, ActivityInstance completedInstance)
        {
            try
            {
                string filePath = SavePathUrl.Get(context);
                if (_Save)
                {
                    if ((!isPathAvailable(filePath)) && (NewDoc))
                    {
                        string           messageBoxText = "此文档为新建文件,请输入正确保存路径!";
                        string           caption        = "提示";
                        MessageBoxButton button         = MessageBoxButton.OK;
                        MessageBoxImage  icon           = MessageBoxImage.Warning;
                        MessageBox.Show(messageBoxText, caption, button, icon);
                        CommonVariable.realaseProcessExit(app);
                        return;
                    }
                    else if (!NewDoc)
                    {
                        app.Documents.Save(true, Word.WdOriginalFormat.wdOriginalDocumentFormat);
                    }
                    else
                    {
                        app.ActiveDocument.SaveAs(filePath);
                    }
                }
                if (_SaveAs)
                {
                    if (!isPathAvailable(filePath))
                    {
                        string           messageBoxText = "另存为应输入正确保存路径!";
                        string           caption        = "提示";
                        MessageBoxButton button         = MessageBoxButton.OK;
                        MessageBoxImage  icon           = MessageBoxImage.Warning;
                        MessageBox.Show(messageBoxText, caption, button, icon);
                        CommonVariable.realaseProcessExit(app);
                        return;
                    }
                    else
                    {
                        app.ActiveDocument.SaveAs2(filePath);
                    }
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(app);
            }

            if (IsExit)
            {
                CommonVariable.realaseProcessExit(app);
            }
        }
Beispiel #4
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag];
            Application        wordApp  = property.GetValue(context.DataContext) as Application;

            try
            {
                float     fontSize     = FontSize.Get(context);
                Int32     leftMargin   = LeftMargin.Get(context);
                Int32     rightMargin  = RightMargin.Get(context);
                Int32     topMargin    = TopMargin.Get(context);
                Int32     bottomMargin = BottomMargin.Get(context);
                Selection sel          = wordApp.Selection;
                Font      font         = sel.Font;

                /*字体设置*/
                font.Size = fontSize;
                if (Font != 0)
                {
                    font.Name = ConvertFont(Font.ToString());
                }
                font.ColorIndex = (WdColorIndex)_FontColor;
                font.Shadow     = Convert.ToInt32(_Shadow);
                font.Bold       = Convert.ToInt32(_FontBold);
                font.Italic     = Convert.ToInt32(_FontItalic);
                if (_FontUnderLine)
                {
                    font.Underline = WdUnderline.wdUnderlineSingle;
                }

                /*段落对齐设置*/
                ParagraphFormat paraFmt;
                paraFmt             = sel.ParagraphFormat;
                paraFmt.Alignment   = (WdParagraphAlignment)_Align;
                sel.ParagraphFormat = paraFmt;

                /*页面设置*/
                PageSetup pgSet = wordApp.ActiveDocument.PageSetup;
                pgSet.LeftMargin   = leftMargin;
                pgSet.RightMargin  = rightMargin;
                pgSet.TopMargin    = topMargin;
                pgSet.BottomMargin = bottomMargin;
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(wordApp);
            }

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag];
            Application        wordApp  = property.GetValue(context.DataContext) as Application;

            try
            {
                string linkName = LinkName.Get(context);
                string linkMark = LinkMark.Get(context);
                string linkAddr = LinkAddr.Get(context);
                string bookMark = BookMark.Get(context);
                string pic      = Pic.Get(context);

                if (linkName != null)
                {
                    Hyperlinks links = wordApp.Selection.Hyperlinks;
                    links.Add(wordApp.Selection.Range, linkAddr, linkMark, "", linkName, linkMark);
                }
                if (bookMark != null)
                {
                    Bookmarks bookmarks = wordApp.Selection.Bookmarks;
                    bookmarks.Add(bookMark);
                }
                if (pic != null)
                {
                    InlineShapes lineshapes = wordApp.Selection.InlineShapes;
                    InlineShape  lineshape  = lineshapes.AddPicture(pic);
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(wordApp);
            }

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Beispiel #7
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag];
            Application        wordApp  = property.GetValue(context.DataContext) as Application;

            try
            {
                string pathUrl = PathUrl.Get(context);
                if (!File.Exists(pathUrl))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "文件不存在,请检查路径有效性!", pathUrl);
                    CommonVariable.realaseProcessExit(wordApp);
                }
                wordApp.Selection.InsertFile(pathUrl);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(wordApp);
            }
            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Beispiel #8
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[WordCreate.GetWordAppTag];
            Application        wordApp  = property.GetValue(context.DataContext) as Application;

            try
            {
                Int32     _movePos = MovePos.Get(context);
                Selection sel      = wordApp.Selection;

                if (Left)
                {
                    if (IsSelect)
                    {
                        sel.MoveLeft(WdUnits.wdCharacter, _movePos, WdMovementType.wdExtend);
                    }
                    else
                    {
                        sel.MoveLeft(WdUnits.wdCharacter, _movePos, WdMovementType.wdMove);
                    }
                }
                else if (Right)
                {
                    if (IsSelect)
                    {
                        sel.MoveRight(WdUnits.wdCharacter, _movePos, WdMovementType.wdExtend);
                    }
                    else
                    {
                        sel.MoveRight(WdUnits.wdCharacter, _movePos, WdMovementType.wdMove);
                    }
                }
                else if (Up)
                {
                    if (IsSelect)
                    {
                        sel.MoveUp(WdUnits.wdLine, _movePos, WdMovementType.wdExtend);
                    }
                    else
                    {
                        sel.MoveUp(WdUnits.wdLine, _movePos, WdMovementType.wdMove);
                    }
                }
                else if (Down)
                {
                    if (IsSelect)
                    {
                        sel.MoveDown(WdUnits.wdLine, _movePos, WdMovementType.wdExtend);
                    }
                    else
                    {
                        sel.MoveDown(WdUnits.wdLine, _movePos, WdMovementType.wdMove);
                    }
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "Word执行过程出错", e.Message);
                CommonVariable.realaseProcessExit(wordApp);
            }

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }