【发布时间】:2020-05-05 11:09:48
【问题描述】:
我正在尝试使用“get.Month”,但是当我运行代码时出现错误:
"TypeError: exSheet.getRange (...). GetValue (...). GetMonth 不是 功能”
当我把“return tempSum;”在“if”之外没有错误并且代码有效......
我尝试使用“.setValue”而不是“return”,但没有帮助。
有人知道怎么解决吗?
function CALC_EX(chosenMonth){
switch(chosenMonth){
case "jan":
chosenMonth = 1;
break;
case "feb":
chosenMonth = 2;
break;
case "mar":
chosenMonth = 3;
break;
case "apr":
chosenMonth = 4;
break;
case "may":
chosenMonth = 5;
break;
case "jun":
chosenMonth = 6;
break;
case "jul":
chosenMonth = 7;
break;
case "aug":
chosenMonth = 8;
break;
case "sep":
chosenMonth = 9;
break;
case "oct":
chosenMonth = 10;
break;
case "nov":
chosenMonth = 11;
break;
case "dec":
chosenMonth = 12;
}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var exSheet = ss.getSheetByName('Expenses');
var tempSum = 0;
for(var i=2;i>0;i++){
var range = exSheet.getRange(i, 5);
var monthCell = exSheet.getRange(i, 5).getValue().getMonth()+1;
if(!range.getValue()){
i = 0;
return tempSum;
}
if(monthCell === chosenMonth){
tempSum = tempSum + exSheet.getRange(i, 12).getValue();
}
}
}
【问题讨论】:
-
将
var monthCell移动到if块下方
标签: google-apps-script google-sheets custom-function