我试图为我的电子表格创建一个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