以下函式的目的是從單元格中檢索一個值并根據該值呼叫不同的函式。當我運行它時,它總是運行默認函式,并且看起來它沒有將值回傳到變數(調查)中,因為當我除錯函式時它顯示為未定義,并且日志值為空:
function hideOrShow() {
var spreadsheet = SpreadsheetApp.getActive();
var survey = spreadsheet.getSheetByName('Store View 2022').getRange(3,1).getvalue;
Logger.log (survey);
if (survey='Delivery') {
showCancellationColumns();
}
else if (survey='C&C') {
showCancellationColumns();
}
else { hideCancellationColumns();}
};
謝謝安妮特
uj5u.com熱心網友回復:
這只是“getValue()”方法中的錯誤
試試這個:
function hideOrShow() {
var spreadsheet = SpreadsheetApp.getActive();
var survey = spreadsheet.getSheetByName('Store View 2022').getRange(3,1).getValue();
Logger.log (survey);
if (survey='Delivery') {
showCancellationColumns();
}
else if (survey='C&C') {
showCancellationColumns();
}
else { hideCancellationColumns();}
};
uj5u.com熱心網友回復:
您的代碼中有兩件事需要更改:
.getValue() (注意大寫的 V--JavaScript 變數區分大小寫)是一個函式,所以它需要括號:
var survey = spreadsheet.getSheetByName('Store View 2022').getRange(3,1).getValue();
那應該解決survey未定義的問題。
當我們測驗相等時(if例如,在陳述句中),我們使用雙等號或三等號:
if (survey=='Delivery')
和
else if (survey=='C&C')
使用單個等號(賦值運算子)撰寫時,if (survey='Delivery')會將值分配'Delivery'給survey.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/418045.html
標籤:
