function createRangeBuilder() {
return DocumentApp.getActiveDocument().newRange();
}
function setRangeBuilderIndexes(startIndex, endIndex) {
var rangeBuilder = createRangeBuilder();
rangeBuilder.addElement(DocumentApp.getActiveDocument().getBody());
var startElementIndex = getStartElementIndex();
var endElementIndex = getEndElementIndex();
rangeBuilder.setStart(startElementIndex, startIndex);
rangeBuilder.setEnd(endElementIndex, endIndex);
return rangeBuilder;
}
function getStartElementIndex() {
return 0;
}
function getEndElementIndex() {
var body = DocumentApp.getActiveDocument().getBody();
return body.getNumChildren() - 1;
}
以上代码会返回一个可以用于创建或更新文档范围的RangeBuilder对象。