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


C# Application.Activate方法代码示例

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


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

示例1: 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

示例2: WordInstance

        public WordInstance(Word.Application app)
        {
            m_App = app;
            m_App.Activate();

            // Get the window handle.
            m_WindowHandle = WindowsApi.GetForegroundWindow();
        }
开发者ID:JoeyScarr,项目名称:word-commandmap,代码行数:8,代码来源:WordInstance.cs

示例3: btnRun_Click


//.........这里部分代码省略.........
                            BodyType.HTML);
                    }

                }
                else
                {
                    //MessageBox.Show("No emails were sent");
                }

                //Send texts. //COMMENTED OUT BEHAVIOUR: If no emails, let the user know
                if (cellListTable.Rows.Count > 0)
                {
                    int columnCount = cellListTable.Columns.Count;
                    StreamReader myEmailStream = new System.IO.StreamReader(tbTextTemplate.Text);
                    string myEmailString = myEmailStream.ReadToEnd();
                    myEmailStream.Close();

                    foreach (DataRow currClient in cellListTable.Rows)
                    {
                        string tempEmailString = myEmailString;
                        tempEmailString = tempEmailString.Replace("[[[[FIRST_NAME]]]]", RemoveSpeech((string)currClient[clientListFirstName]));
                        tempEmailString = tempEmailString.Replace("[[[[IRD_NUMBER]]]]", RemoveSpeech((string)currClient[clientListIRD]));
                        SendEmail(
                            RemoveSpeech((string)currClient[clientListCellphone] + "@sms.tnz.co.nz"),
                            tempEmailString,
                            "",
                            BodyType.Text);
                    }

                }
                else
                {
                    //MessageBox.Show("No emails were sent");
                }

                //Create a temp file for the mail merge data, and dump it all out. //COMMENTED OUT BEHAVIOUR: If no letters, let the user know
                if (postListTable.Rows.Count > 0)
                {
                    String mergeFileLocation = System.IO.Path.GetTempFileName() + ".csv";
                    FileStream mergeOutputStream = File.Create(mergeFileLocation);

                    //write headers
                    int columnCount = postListTable.Columns.Count;
                    for (int i = 0; i < columnCount; i++)
                    {
                        AddText(mergeOutputStream, postListTable.Columns[i].ColumnName);
                        if (i != columnCount - 1) AddText(mergeOutputStream, ",");
                    }
                    AddText(mergeOutputStream, Environment.NewLine);

                    //write data
                    foreach (DataRow currClient in postListTable.Rows)
                    {
                        for (int i = 0; i < columnCount; i++)
                        {
                            AddText(mergeOutputStream, (string)currClient[i]);
                            if (i != columnCount - 1) AddText(mergeOutputStream, ",");
                        }
                        AddText(mergeOutputStream, Environment.NewLine);
                    }
                    mergeOutputStream.Close();

                    //Run the mail merge
                    Object oMailMergeFile = tbLetterTemplate.Text;
                    Object oMissing = System.Reflection.Missing.Value;
                    Object oFalse = false;
                    Object oTrue = true;
                    Object oSql = "Select * from [Table1$]";

                    Word._Application oWord = new Word.Application();
                    oWord.Visible = false;
                    oWord.ScreenUpdating = false;
                    Word._Document myDoc = oWord.Documents.Add(ref oMailMergeFile, ref oMissing, ref oMissing, ref oMissing);
                    myDoc.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters;
                    myDoc.MailMerge.OpenDataSource(@mergeFileLocation, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oSql, ref oMissing, ref oMissing, ref oMissing);
                    myDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
                    myDoc.MailMerge.Execute(ref oFalse);
                    saveMergeDocs(oWord);
                    myDoc.Close(ref oFalse, ref oMissing, ref oMissing);

                    //Make the merge visible
                    oWord.Visible = true;
                    oWord.ScreenUpdating = true;
                    oWord.Activate();

                    File.Delete(mergeFileLocation);
                }
                else
                {
                    //MessageBox.Show("No letters were printed");
                }

                //DEBUG: comment the following out for production
                //oExcel.Workbooks.Open(mergeFileLocation, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            }
            else
            {
                MessageBox.Show("Please set either email, text, or letter to something other than \"Do Not Send\"");
            }
        }
开发者ID:Oblongmana,项目名称:Bulk-Distributor,代码行数:101,代码来源:Form1.cs

示例4: PustoString

        private void ведомостьТрубопроводовToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Word.Application app;
            Word.Document doc;
            Object missingObj = System.Reflection.Missing.Value;
            Object trueObj = true;
            Object falseObj = false;
            app = new Word.Application();
            Object templatePathObj = Application.StartupPath + "\\vt.docx";
            try
            {
                doc = app.Documents.Add(ref templatePathObj, ref missingObj, ref missingObj, ref missingObj);
                doc.Activate();
                doc = app.ActiveDocument;
                //Колонтитул (шифр проекта)
                /* foreach (Word.Section wordSection in doc.Sections)
                 {
                     Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                     //footerRange.Font.Size = 20;
                     //footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed;
                     footerRange.Text = PustoString(ShifrTextBox.Text);
                 }*/

                Microsoft.Office.Interop.Word.Find fnd = app.Selection.Find;

                //Колонтитул (шифр проекта)
                foreach (Word.Section wordSection in doc.Sections)
                 {
                     Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                    //footerRange.Font.Size = 20;
                    //footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed;

                    //footerRange.Text = PustoString(ShifrTextBox.Text);
                    Microsoft.Office.Interop.Word.Find fndС =footerRange.Find;

                    fndС.ClearFormatting();
                    fndС.Text = "{cltl}";
                    fndС.Replacement.ClearFormatting();
                    fndС.Replacement.Text = PustoString(ShifrTextBox.Text);
                    ExecuteReplace(fndС);
                }

                // Температура рабочая / max, C (от минус <> до плюс <>)

                fnd.ClearFormatting();
                fnd.Text = "{T}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text= "от " + Describe(TFromNumericUpDown.Value) + " до " + Describe(TToNumericUpDown.Value) + " / " + Pusto(TMaxNumericUpDown.Value);
                ExecuteReplace(fnd);
                //Название секции
                fnd.ClearFormatting();
                fnd.Text = "{Name}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text = SectionNameTextBox.Text;
                ExecuteReplace(fnd);
                //Давление: Р(усл) кгс/см2
                fnd.ClearFormatting();
                fnd.Text = "{P_usl}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text = PustoString(PUslComboBox.SelectedItem.ToString());
                ExecuteReplace(fnd);
                //Давление: Р(раб) кгс/см2
                fnd.ClearFormatting();
                fnd.Text = "{P_rab}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text = Pusto(PRabNumericUpDown.Value);
                ExecuteReplace(fnd);
                //Давление: Р(расч) кгс/см2
                fnd.ClearFormatting();
                fnd.Text = "{P_ras}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text = Pusto(PRaschNumericUpDown.Value);
                ExecuteReplace(fnd);
                //Давление: Р(проч) кгс/см2
                fnd.ClearFormatting();
                fnd.Text = "{P_pro}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text =Pusto(PProchNumericUpDown.Value);
                ExecuteReplace(fnd);
                //Давление: Р(плот) кгс/см2
                fnd.ClearFormatting();
                fnd.Text = "{P_plo}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text = Pusto(PPlotNumericUpDown.Value);
                ExecuteReplace(fnd);
                //Давление: Р(герм) кгс/см2
                fnd.ClearFormatting();
                fnd.Text = "{P_ger}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text = Pusto(PGermNumericUpDown.Value);
                ExecuteReplace(fnd);
                //Способ испытания: Р(проч)-"Г" или "П"
                fnd.ClearFormatting();
                fnd.Text = "{M_pro}";
                fnd.Replacement.ClearFormatting();
                fnd.Replacement.Text = PustoString(PProchMethodComboBox.SelectedItem.ToString());
                ExecuteReplace(fnd);
                //Способ испытания: Р(плот)-"Г" или "П"
                fnd.ClearFormatting();
                fnd.Text = "{M_plo}";
//.........这里部分代码省略.........
开发者ID:Rosov,项目名称:Sapr_piping,代码行数:101,代码来源:Form1.cs

示例5: CreateWordApp

 static Wd.Application CreateWordApp()
 {
     var app = new Wd.Application() { Visible = true };
     app.Activate(true);
     return app;
 }
开发者ID:beachandbytes,项目名称:GorillaDocs,代码行数:6,代码来源:WordApplicationHelper.cs


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