Word.RangeLocation enum
表示范围的位置。 您可以通过在不同的对象(例如 Word)上调用 getRange 来获取范围。段落和 Word。ContentControl.
注解
使用方
示例
// 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" | 和 |
| end = "End" | 对象的终点。 对于段落,它是 EOP 之前 (段落) 结束的点。 对于内容控制,它是结束标记之前的点。 |
| start = "Start" | 对象的起点。 对于内容控制,它是开始标记后的点。 |
| whole = "Whole" | 对象的整个范围。 如果对象是段落内容控件或表内容控件,则还包括内容控件后的 EOP 或 Table 字符。 |