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


C# Microsoft.Office.Interop.Word.Application.Activate方法代码示例

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


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

示例1: ReviseInMSWord

 /// <summary>This function opens page text in Microsoft Word for editing.
 /// Just close Word after editing, and the revised text will appear in
 /// Page.text variable.</summary>
 /// <remarks>Appropriate PIAs (Primary Interop Assemblies) for available MS Office
 /// version must be installed and referenced in order to use this function. Follow
 /// instructions in "Compile and Run.bat" file to reference PIAs properly in compilation
 /// command, and then recompile the framework. Redistributable PIAs can be downloaded from
 /// http://www.microsoft.com/downloads/results.aspx?freetext=Office%20PIA</remarks>
 public void ReviseInMSWord()
 {
     #if MS_WORD_INTEROP
     if (string.IsNullOrEmpty(text))
         throw new WikiBotException(Bot.Msg("No text on page to revise in Microsoft Word."));
     Microsoft.Office.Interop.Word.Application app =
         new Microsoft.Office.Interop.Word.Application();
     app.Visible = true;
     object mv = System.Reflection.Missing.Value;
     object template = mv;
     object newTemplate = mv;
     object documentType = Microsoft.Office.Interop.Word.WdDocumentType.wdTypeDocument;
     object visible = true;
     Microsoft.Office.Interop.Word.Document doc =
         app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
     doc.Words.First.InsertBefore(text);
     text = null;
     Microsoft.Office.Interop.Word.DocumentEvents_Event docEvents =
         (Microsoft.Office.Interop.Word.DocumentEvents_Event) doc;
     docEvents.Close +=
         new Microsoft.Office.Interop.Word.DocumentEvents_CloseEventHandler(
             delegate { text = doc.Range(ref mv, ref mv).Text; doc.Saved = true; } );
     app.Activate();
     while (text == null);
     text = Regex.Replace(text, "\r(?!\n)", "\r\n");
     app = null;
     doc = null;
     GC.Collect();
     GC.WaitForPendingFinalizers();
     GC.Collect();
     GC.WaitForPendingFinalizers();
     Bot.LogEvent(
         Bot.Msg("Text of \"{0}\" page was revised in Microsoft Word."), title);
     #else
     throw new WikiBotException(Bot.Msg("Page.ReviseInMSWord() function requires MS " +
         "Office PIAs to be installed and referenced. Please, see remarks in function's " +
         "documentation in \"Documentation.chm\" file for additional instructions.\n"));
       #endif
 }
开发者ID:wikigit,项目名称:Picasa-Review-Bot,代码行数:47,代码来源:DotNetWikiBot.cs


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