Word.RangeLocation enum
注解
示例
// 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: Word.RangeCollection = 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: Word.RangeCollection = 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 或表字符后面的点。 |
before = "Before" | 仅适用于内容控件。 它是开始标记之前的点。 |
content = "Content" | “Start”和“End”之间的范围。 |
end = "End" | 对象的终点。 对于段落,它是 EOP 之前的点。 对于内容控件,它是结束标记之前的点。 |
start = "Start" | 对象的起点。 对于内容控件,它是开始标记后面的点。 |
whole = "Whole" | 对象的整个范围。 如果对象是段落内容控件或表内容控件,则内容控件后面的 EOP 或 Table 字符也包括在内。 |