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


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

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


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

示例1: GetFullTextOfDocument

 /* The question arises here: why didn't I just use content.Text to acquire the content. It's because it returns a different text
  * from what the setRange() function works on (and using setRange later is unavoidable). You might be asking then, why not use
  * the TextRetrievalMode and ViewType properties of the content, but turns out they can't give you the same text that setRange()
  * is working on either. So unfortunately the ugly solution here seems unavoidable. The Characters array of content is also not usable.
  * Sadly, this solution produces a noticable slowdown with long documents, and I couldn't find a better solution with the Word API. */
 private string GetFullTextOfDocument(Word.Range content)
 {
     int length = content.End;
     StringBuilder sb = new StringBuilder(content.End);
     for (int i = 0; i < length; i++)
     {
         content.SetRange(i, i + 1);
         /* In certain cases a null is returned instead of a character (for example at the place of the special character representing
          * the starting point of a Hyperlink block, but in other simpler cases too. There is no information about these in the
          * documentation, so I couldn't write a state machine for it. ) But if I didn't take these into consideration then it woulddn't
          * be aligned correctly with setRange(), so I have to substitute it with something. Later it turned out that in some cases
          * there are two characters returned by setRange(i, i+1): The '\r\a' symbol representing the end of a cell takes up two character
          * spaces as a string, but only one in the Range logic. */
         if (content.Text == null)
         {
             sb.Append(' ');
         }
         else
         {
             if (content.Text.Length == 1)
                 sb.Append(content.Text);
             else
                 sb.Append(content.Text[0]);
         }
     }
     return sb.ToString();
 }
开发者ID:ggmod,项目名称:WordSyntaxHighlighter,代码行数:32,代码来源:RegexFindForm.cs


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