应该使用什么结束标记来将范围扩展到段落的末尾?

What ending marks should be used to extend a range to the end of the paragraph?

我正在编写一个单词加载项,但不清楚如何使用范围 class.

的 getNextTextRange(endingMarks, trimSpacing) 方法

具体来说,我想 select 从当前 selected 范围开始到段落结尾的新范围。

方法的 API

endingMarks string[] Required. The punctuation marks and/or other ending marks as an array of strings

如果您想 select 到下一个逗号、句点甚至 space,那就足够清楚了。但是,您应该为段落、换行符或文档结尾使用什么结束标记?

我尝试过使用“\n”、“^p”和“¶”,但其中 none 似乎有效。

          var nr = selection.getNextTextRange(['¶'],true);
           nr.load("isEmpty,text");
           await context.sync();
           console.log('nr='+nr.text);
         } catch(e) {
          console.log("error, soz");
          console.log(e);
         }

给定一个文档,该文档由一个文本段落和一个空白段落组成,该段落的第一个单词突出显示,此加载项抛出 RichApi.Error

We couldn't find the item you requested.

我希望它打印出该段落的剩余部分。

如果我了解您的情况,您可以使用 ParagraphCollection.getFirst() method. Please install the Script Lab 工具。打开名为 "Get paragraph from insertion point" 的示例作为示例。

让我扩展一下 rick-kirkham 的回答,以防它能帮助遇到我这种情况的其他人。这与此处给出的答案基本相同

好的,这是我的示例 word 文档:

The rain in Spain falls. Mainly on the plain.

Alice stepped through the looking glass. What did she see?

And there endeth the lesson. Amen.

用户在第二段中选择了“stepped”,我想知道该段其余部分的文字是用那个词说的。我也想知道当时的文字是怎么说的。

var doc = context.document;
var selection = doc.getSelection(); 
selection.load("isEmpty,text");
await context.sync();
console.log(selection.text); //prints stepped

var startRange = selection.getRange("start"); 
var endRange = selection.paragraphs.getLast().getRange("start");
var deltaRange = startRange.expandTo(endRange);
context.load(deltaRange);
await context.sync();
console.log(deltaRange.text); //prints "Alice"

startRange = selection.getRange("end"); 
endRange = selection.paragraphs.getLast().getRange("end");
deltaRange = startRange.expandTo(endRange);
context.load(deltaRange);

await context.sync();
console.log(deltaRange.text); // prints "through the looking glass. What did she see?"

我的错误是过于专注于弄清楚“结束标记”可能意味着什么以及如何使用它们来实现这一目标。 (尽管我仍然希望在 API 规范中详细说明这一点。)