Word.RangeLocation enum
Represents the location of a range. You can get range by calling getRange on different objects such as Word.Paragraph and Word.ContentControl.
Remarks
Used by
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-paragraph-on-insertion-point.yaml
// Gets complete sentences from the insertion point to the end of its paragraph.
await Word.run(async (context) => {
const selection: Word.Range = context.document.getSelection();
const sentences: Word.RangeCollection = selection.getTextRanges(["."], false);
sentences.load("$none");
await context.sync();
const firstSentence: Word.Range = sentences.items[0];
const paragraphEnd: Word.Range = selection.paragraphs.getFirst().getRange(Word.RangeLocation.end);
const remainingRange: Word.Range = firstSentence.expandTo(paragraphEnd);
const sentencesToTheEndOfParagraph: Word.RangeCollection = remainingRange.getTextRanges(["."], false);
sentencesToTheEndOfParagraph.load("text");
await context.sync();
console.log("Sentences from the current sentence to the paragraph end:");
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's the point after the EOP or Table characters. |
| before = "Before" | For content control only. It's the point before the opening tag. |
| content = "Content" | The range between |
| end = "End" | The ending point of the object. For paragraph, it's the point before the EOP (end of paragraph). For content control, it's the point before the closing tag. |
| start = "Start" | The starting point of the object. For content control, it's 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. |