Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google脚本:找不到从电子表格获取数据的范围_Google Apps Script - Fatal编程技术网

Google apps script Google脚本:找不到从电子表格获取数据的范围

Google apps script Google脚本:找不到从电子表格获取数据的范围,google-apps-script,Google Apps Script,我正在尝试通过谷歌应用程序脚本获取电子邮件。如果某人的生日是今天,我会收到一封提醒邮件。我有一个谷歌表格,上面已经有了这些数据。但我在一些事情上有问题。首先,下面是我正在运行的代码 var-activeSheet=SpreadsheetApp.getActiveSpreadsheet(); var birthdaysSheet=activeSheet.getSheetByName(“数据”); var settingsSheet=activeSheet.getSheetByName(“设置”)

我正在尝试通过谷歌应用程序脚本获取电子邮件。如果某人的生日是今天,我会收到一封提醒邮件。我有一个谷歌表格,上面已经有了这些数据。但我在一些事情上有问题。首先,下面是我正在运行的代码

var-activeSheet=SpreadsheetApp.getActiveSpreadsheet();
var birthdaysSheet=activeSheet.getSheetByName(“数据”);
var settingsSheet=activeSheet.getSheetByName(“设置”);
var sendmailto=settingsSheet.getRange(“B4”).getValue();
函数emailAlert(){
if(turnOnEmailNotice.toLowerCase()=“否”)
{ 
Logger.log(“电子邮件通知未打开。系统将退出”);
出口
} 
//获取工作表中已填充行的总数。
var currentRowAT=2;
var currentCellValueAT=“开始”;
而(currentCellValueAT!=“”){
如果(currentCellValueAT=birthdaysSheet.getRange(“A”+currentRowAT.getValue()!=”){
currentRowAT=currentRowAT+1;
}
}
var birthdaysSheetLastRow=currentRowAT-1;
//获取今天的日期(包括月份、日期和年份)
var today=新日期();
var todayMth=today.getMonth()+1;
var todayDate=today.getDate();
var todayYear=today.getFullYear();
对于(k=2;k
问题:

  • 当我在
    var firstName=birthdaysSheet.getRange(“A”+行).getValue()获取范围时出错

    --错误:未找到范围

  • 我认为我的代码得到年龄似乎也是错误的

  • 如果我只使用第一行,那么年龄将以
    未定义的形式出现


  • 我想知道如果您的第一个循环的结构如下所示,是否会更好:

    //Get the total number of filled row in the sheet.
    var currentRowAT = 2;
    var currentCellValueAT = "start";
    var thisRow, theBirthday = "";
    
    var birthdayData = birthdaysSheet.getRange(1, 1, birthdaysSheet.getLastRow()); //Get all of column A data
    
    for (var i=0;i<birthdayData.length;i+=1) {
      thisRow = birthdayData[i];
      theBirthday = thisRow[0];
      if (theBirthday === "") {
        var birthdaysSheetLastRow = currentRowAT - 1;
        break;  //Stop looping through the data
      };
    };
    
    //获取工作表中已填充行的总数。
    var currentRowAT=2;
    var currentCellValueAT=“开始”;
    var thisRow,theBirthday=“”;
    var birthdayData=birthdaysSheet.getRange(1,1,birthdaysSheet.getLastRow())//获取列A中的所有数据
    
    对于(var i=0;i问题已经解决。我只是在excel工作表中运行了脚本。它工作了。没有改变任何东西


    谢谢大家的帮助。

    第12行:
    exit
    。JavaScript中没有
    exit
    。您需要使用
    return;
    在第9行有一个变量名
    turnOnEmailNotice
    ,但该名称从未在任何地方声明或设置。现在,您使用
    getValue()获得单个单元格值
    method。这太慢了。最好在一次操作中获取所有数据,然后循环遍历数据数组。我只获取一个人的名字。我不想要整列,我一次只获取一个人的名字。@SandyGood请检查我更新的问题。我在if条件下使用了
    turnOnEmailNotice
    //Get the total number of filled row in the sheet.
    var currentRowAT = 2;
    var currentCellValueAT = "start";
    var thisRow, theBirthday = "";
    
    var birthdayData = birthdaysSheet.getRange(1, 1, birthdaysSheet.getLastRow()); //Get all of column A data
    
    for (var i=0;i<birthdayData.length;i+=1) {
      thisRow = birthdayData[i];
      theBirthday = thisRow[0];
      if (theBirthday === "") {
        var birthdaysSheetLastRow = currentRowAT - 1;
        break;  //Stop looping through the data
      };
    };