我正在尝试在 Google 表格中运行自定义功能。我没有收到编译错误,但是当我尝试调用该函数时,我收到 #ERROR 以及一条消息,
您无权调用 sort
有没有办法解决这个问题?range.sort
如果不可用,如何在自定义函数中对范围进行排序?
这是我的代码:
function installmentPrice(priceRange, measuringPeriod, lowestDays, discount)
{
measuringPeriod = measuringPeriod || 5;
lowestDays = lowestDays || 1;
discount = discount || 1;
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var tempRange = sheet.getRange("C3:C9");
var newRange = tempRange.offset(0,0,measuringPeriod);
newRange.sort(newRange.getColumn());
Logger.log(newRange.getValues());
var lowestSum = 0;
var installmentPx = 0;
for (i=0; i<= lowestDays; i++) {
lowestSum = lowestSum + newRange[i];
}
lowestSum = lowestSum/lowestDays;
installmentPx = discount * lowestSum;
return installmentPx;
}