Identifying a Range

A Range has several properties to help identify it. The get_Information methods takes a parameter of type WdInformation and returns information as an object about the Range depending on the enumerated value that is passed to method. If you call get_Information on a Range with an enumerated type that is not applicable, get_Information will return 1 as a return value.

This is an example of getting information associated with the Range.

[sourcecode language=”csharp”]

public void sampleCode()
{
Object missing = System.Reflection.Missing.Value;
Word.Range r = Globals.ThisAddIn.Application.ActiveDocument.Range(ref missing, ref missing);

r.Text = "This\nis\na\ntest.";

object startIndex = 0;
object endIndex = 9;

Word.Range r2 = Globals.ThisAddIn.Application.ActiveDocument.Range(ref startIndex, ref endIndex);
r2.InsertAfter("\n");

for (int i = 1; i < 27; i++)
{
GetInfo(r2, (Word.WdInformation)i);
}
}

private void GetInfo(Word.Range r, Word.WdInformation info)
{
string result = String.Format(
"Range.Information({0}) returns {1}.\n",
info.ToString(), r.get_Information(info));
r.InsertAfter(result);
}

[/sourcecode]

You can learn output (return value) of the code yourself.

<< BACK

Tinggalkan Balasan