Word.RangeLocation enum

注釈

[ 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

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

フィールド

after = "After"

オブジェクトの後のポイント。 オブジェクトが段落コンテンツ コントロールまたはテーブル コンテンツ コントロールの場合は、EOP または Table 文字の後のポイントになります。

before = "Before"

コンテンツ コントロールの場合のみ。 これは、開始タグの前のポイントです。

content = "Content"

'Start' と 'End' の範囲。

end = "End"

オブジェクトの終了ポイント。 段落の場合、これは EOP の前のポイントです。 コンテンツ コントロールの場合は、終了タグの前のポイントです。

start = "Start"

オブジェクトの開始点。 コンテンツ コントロールの場合は、開始タグの後のポイントです。

whole = "Whole"

オブジェクトの範囲全体。 オブジェクトが段落コンテンツ コントロールまたはテーブル コンテンツ コントロールの場合は、コンテンツ コントロールの後の EOP または Table 文字も含まれます。