Word.RangeLocation enum

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-paragraph-on-insertion-point.yaml

await Word.run(async (context) => {
  // Get the complete sentence (as range) associated with the insertion point.
  const sentences = context.document
    .getSelection()
    .getTextRanges(["."] /* Using the "." as delimiter */, false /*means without trimming spaces*/);
  sentences.load("$none");
  await context.sync();

  // Expand the range to the end of the paragraph to get all the complete sentences.
  const sentencesToTheEndOfParagraph = sentences.items[0]
    .getRange()
    .expandTo(
      context.document
        .getSelection()
        .paragraphs.getFirst()
        .getRange(Word.RangeLocation.end)
    )
    .getTextRanges(["."], false /* Don't trim spaces*/);
  sentencesToTheEndOfParagraph.load("text");
  await context.sync();

  for (let i = 0; i < sentencesToTheEndOfParagraph.items.length; i++) {
    console.log(sentencesToTheEndOfParagraph.items[i].text);
  }
});

Fields

after = "After"

The point after the object. If the object is a paragraph content control or table content control, it is the point after the EOP or Table characters.

before = "Before"

For content control only. It is the point before the opening tag.

content = "Content"

The range between 'Start' and 'End'.

end = "End"

The ending point of the object. For paragraph, it is the point before the EOP. For content control, it is the point before the closing tag.

start = "Start"

The starting point of the object. For content control, it is the point after the opening tag.

whole = "Whole"

The object's whole range. If the object is a paragraph content control or table content control, the EOP or Table characters after the content control are also included.