我試圖爲我的電子表格創建一個Google Apps腳本。它應該運行一個函數,並根據今天的日期將結果返回到電子表格中的特定工作表。當只將行添加到活動工作表而不是特定工作表時,它可以正常工作。此外,代碼在腳本編輯器中保存得很好,所以我會假設沒有重大錯誤。也許我已經在Javascript中列出了錯誤,或者我不明白代碼中的根本錯誤。我傾向於我的IF ELSE,或者我如何設置活動電子表格,然後是表格,但不知道確切。任何幫助,將不勝感激。下面是代碼基礎:如果ELSE基於今天的日期附加行到月表
function CheckDateInsertData() {
function infoDate(){ this gets today's date}
if (infoDate() >= 2016/01/01 && infoDate() <= 2016/01/31) {
function GetData1{
//this retrieves necessary data, working when not using IF ELSE statements and only single active sheet, without calling sheet by name.
var Data =.......... ;
appendData(Data);
function appendData(Data){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet.setActiveSheet(sheet.getSheetByName("January"));
sheet.appendRow(['Date', 'Price', 'Location']);
}
}
} else if (infoDate() >= 2016/02/01 && infoDate() <= 2016/02/29){
function GetData2{
var Data = ........;
appendData(Data);
function appendData(Data){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet.setActiveSheet(sheet.getSheetByName("February"));
sheet.appendRow(['Date', 'Price', 'Location']);
}
}
}
}
'infoDate()'返回什麼數據類型? '2016/01/01'是算術除法,它不是日期對象或日期的字符串表示。 – Barmar
看起來你已經有了其他函數中的函數。我不會像這樣構造代碼。你可以將函數放入對象中,並將對象放入其他對象中。我想有可能在其他函數中有函數,並讓它們運行。你說代碼正在工作。你爲什麼在其他函數中嵌套函數? –
啊,你是對的。它作爲一個字符串返回。所以,如果我擺脫了函數infoDate()並使其var todaysDate = new Date();那會解決那個部分?那麼我如何將它與IF語句中的手動輸入日期進行比較? – Jason