Word.RangeLocation enum

表示范围的位置。 您可以通过在不同的对象(例如 Word)上调用 getRange 来获取范围。段落和 Word。ContentControl.

注解

API 集:WordApi 1.3

使用方

示例

// 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);
  }
});

字段

after = "After"

对象之后的点。 如果对象是段落内容控件或表内容控件,则它是 EOP 或表字符之后的点。

before = "Before"

仅用于内容控制。 这是开场标签之前的点。

content = "Content"

和 end之间的范围start。

end = "End"

对象的终点。 对于段落,它是 EOP 之前 (段落) 结束的点。 对于内容控制,它是结束标记之前的点。

start = "Start"

对象的起点。 对于内容控制,它是开始标记后的点。

whole = "Whole"

对象的整个范围。 如果对象是段落内容控件或表内容控件,则还包括内容控件后的 EOP 或 Table 字符。