本文整理汇总了C#中Microsoft.Office.Interop.Word.GetCleanedText方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.GetCleanedText方法的具体用法?C# Microsoft.Office.Interop.Word.GetCleanedText怎么用?C# Microsoft.Office.Interop.Word.GetCleanedText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Word.GetCleanedText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AdjustRange
private Word.Range AdjustRange(Word.Range range, Annotation annotation)
{
String initialText = range.GetCleanedText();
bool match = IsMatch(range, annotation);
String rangeText = "";
int offset = Int32.MinValue;
object rangeStart = range.Start;
object rangeEnd = range.End;
int rangeLength = (int)rangeEnd - (int)rangeStart - 1;
object selectionStart = annotation.Selection[0];
try
{
while (!match)
{
offset = range.Text.IndexOf((char)selectionStart);
object start = range.Start + (int)offset;
object end = range.Start + rangeLength + (int)offset;
do
{
//extend the range to the selection length
range = document.Range(ref start, ref end);
range.TextRetrievalMode.IncludeHiddenText = false;
rangeText = range.GetCleanedText();
end = (int)end + 1;
} while (rangeText.Length != annotation.Selection.GetCleanedText().Length);
if (IsMatch(range, annotation))
{
match = true;
}
else if (offset < 0)
{
//if not found return initial range
return document.Range(ref rangeStart, ref rangeEnd);
}
else if (offset == 0)
{
start = (int)start + 1;
end = (int)start + 1;
range = document.Range(ref start, ref end);
}
}
}
catch (NullReferenceException nre)
{
Log.Exception(nre);
return null;
}
return range;
}
示例2: IsMatch
/// <summary>
/// Determines if a Word range is matching the selected text for an annotation
/// </summary>
/// <param name="range">The Word range to be verified.</param>
/// <param name="annotation">The displayed annotation.</param>
/// <returns>True if the range contains the annotated text and does not start with white spaces.</returns>
private bool IsMatch(Word.Range range, Annotation annotation)
{
String rangeText = range.GetCleanedText();
String selectedText = annotation.Selection.GetCleanedText();
bool match = (rangeText == selectedText) && (range.Text[0] == annotation.Selection[0]);
match = match && (!range.Text[0].ToString().IsWhiteSpace());
match = match && (!range.Text[range.Text.Length -1].ToString().IsWhiteSpace());
return match;
}